-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
private readonly AppDbContext _ctx; | ||
private readonly UserManager<AppUser> _userm; | ||
|
||
public OrganizationController(AppDbContext context, UserManager<AppUser> usermanager,ILogger<OrganizationController> logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
There was a problem hiding this 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() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OrganizationsController.cs
|
||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FirstOrDefaultAsync
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
webapp/Entity/Contact.cs
Outdated
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chopamiz
public virtual ICollection<Invoice> Invoices { get; set; } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chopamiz
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bu kecha bajarilgan
@wahid-d OrganizationController To'g'riladim, tekshirib bering |
var user = await _userm.GetUserAsync(User); | ||
if(user == null) | ||
{ | ||
return Unauthorized(); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existingOrgs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bajarildi
if (createdOrgs == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bajarildi
Organizations = createdOrgs, | ||
totalOrganizationsCount = totalOrganizations, | ||
totalPages = (int)Math.Ceiling(totalOrganizations / (double)limit), | ||
Page = page, | ||
Limit = limit |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bajarildi
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra spaces
[HttpGet] | ||
public IActionResult New() => View(new CreateOrganizationViewModel()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*.ToOrganizationViewModel()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bajarildi
if (org == default) | ||
{ | ||
return NotFound(); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LogError()
There was a problem hiding this comment.
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}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LogError()
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return View(model);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bajarildi
var org = new Organization() | ||
{ | ||
Id = Guid.NewGuid(), | ||
Name = model.Name, | ||
Address = model.Address, | ||
Phone = model.Phone, | ||
Email = model.Email, | ||
OwnerId = user.Id | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2- loggin kerak emas.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
show ga qilib quydim
sizda bazi actionlar nomi notogri. Masalan: Tugatgandan keyin kod ni test qilish kerak. Ishlaydimi yoqmi?oddiy viewlar yaratib olib uiga etibor bermay bir test qilib controller ishlaydimi yoqmi? |
OrganizationController finished and ready to review
Closes #28