Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #28 Khurshid/organization controller #54

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

KhurshidUmid
Copy link
Contributor

@KhurshidUmid KhurshidUmid commented Feb 11, 2022

OrganizationController finished and ready to review
Closes #28

private readonly AppDbContext _ctx;
private readonly UserManager<AppUser> _userm;

public OrganizationController(AppDbContext context, UserManager<AppUser> usermanager,ILogger<OrganizationController> logger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Member

@wahidustoz wahidustoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

[HttpGet]
public async Task<IActionResult> Created()
Copy link
Member

@wahidustoz wahidustoz Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrganizationListViewModel

  • List Organizations
  • int page
  • int limit
  • int totalPages
  • int total

{

[Authorize]
public class OrganizationController : Controller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrganizationsController.cs

Comment on lines 85 to 86


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ochiramiz

}

[HttpPost]
public async Task<IActionResult> UpdateModel(Guid id, OrganizationModel model)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateOrganizationViewModel.cs

return RedirectToAction("Created");
}

var returnedModel = _ctx.Organizations.FirstOrDefault(o => o.Id == id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FirstOrDefaultAsync

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existingOrg



[HttpGet]
public IActionResult GetById(OrganizationViewModel org)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guid id,

OrganizationViewModel qaytaradi. idga ega Organization

Comment on lines 30 to 31


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chopamiz

Comment on lines 30 to +31
public virtual ICollection<Invoice> Invoices { get; set; }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chopamiz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invoices qolsinmi?

@@ -1,5 +1,6 @@
using webapp.Entity;
using webapp.ViewModel;
using webapp.ViewModels;

namespace webapp.Extensions;
public static class ToViewModels
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContactEntityExtensions.cs

@KhurshidUmid siz OrganizationExtensions.cs class ga hamma kodizni ko'chirasiz.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bu kecha bajarilgan

@KhurshidUmid
Copy link
Contributor Author

@wahid-d OrganizationController To'g'riladim, tekshirib bering

Comment on lines 43 to 47
var user = await _userm.GetUserAsync(User);
if(user == null)
{
return Unauthorized();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bu actionda user ishlatilmagani uchun bu shart emas. Unauthorizedni esa tepadagi attribute o'zi qaytaradi shundoq ham

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bajarildi

return Unauthorized();
}

var createdOrgs = await _ctx.Organizations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existingOrgs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bajarildi

Comment on lines 60 to 64
if (createdOrgs == null)
{
return NotFound();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yoq, prosta bironta ham Oranizationsiz qaytarilaveradi. NotFound faqat izlangan ma'lumot topilmaganda qaytariladi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bajarildi

Comment on lines 69 to 73
Organizations = createdOrgs,
totalOrganizationsCount = totalOrganizations,
totalPages = (int)Math.Ceiling(totalOrganizations / (double)limit),
Page = page,
Limit = limit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just PaginatedListViewModel.cs from ViewModels folder.

  • Just supply the Items type for generic class. For this action, it's OrganizationViewModel

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bajarildi

Comment on lines 76 to 79




Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra spaces

Comment on lines 196 to 197
[HttpGet]
public IActionResult New() => View(new CreateOrganizationViewModel());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action should go upto right before Create action.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bajarildi

return NotFound();
}

return View(org.ToOrgModel());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*.ToOrganizationViewModel()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bajarildi

Comment on lines 208 to 211
if (org == default)
{
return NotFound();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You dont need this since you already have AnyAsync above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bajarildi

}
catch (Exception e)
{
_logger.LogWarning($"Error occured while updating organization:\n{e.Message}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogError()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bajarildi

}
catch (Exception e)
{
_logger.LogWarning($"Error occured while updating organization:\n{e.Message}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogError()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bajarildi

Address = u.Address,
}).ToListAsync();

var totalOrganizations = existingOrgs.Count();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bu xato. Paginationni ishdan chiqaradi.

var totalOrganizations = await _ctx.Organizations.CountAsync();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bajarildi

{
_logger.LogInformation($"Model validation failed for {JsonSerializer.Serialize(model)}");
// return BadRequest("Organization properties are not valid.");
return View();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return View(model);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bajarildi

Comment on lines +82 to +90
var org = new Organization()
{
Id = Guid.NewGuid(),
Name = model.Name,
Address = model.Address,
Phone = model.Phone,
Email = model.Email,
OwnerId = user.Id
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Organization(model.Name, model.Address, model.Phone, model.Email, user.Id);

Organization entity ichida default constructorni obsolete qilib qo'yish kerak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hop

await _ctx.Organizations.AddAsync(org);
await _ctx.SaveChangesAsync();
_logger.LogInformation($"New organization added with ID: {org.Id}");
_logger.LogInformation($"New EmployeeOrganization added with ID: {user.Id}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2- loggin kerak emas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hop

_logger.LogInformation($"New organization added with ID: {org.Id}");
_logger.LogInformation($"New EmployeeOrganization added with ID: {user.Id}");

return RedirectToAction(nameof(Created));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created degan Action yoqku bizda?

Copy link
Contributor Author

@KhurshidUmid KhurshidUmid Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show ga qilib quydim

@wahidustoz
Copy link
Member

@KhurshidUmid

sizda bazi actionlar nomi notogri. Masalan: /{id}/edit route update qiladigan view qaytaradi. /{id}/update route o'sha ma'lumotni update qiladi.

Tugatgandan keyin kod ni test qilish kerak. Ishlaydimi yoqmi?

oddiy viewlar yaratib olib uiga etibor bermay bir test qilib controller ishlaydimi yoqmi?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OrganizationController.cs
2 participants