// [Authorize("Admin")] public async Task <IActionResult> PostEvidenceStat([FromBody] EvidenceFormViewModel evidenceFormViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string message; var evidenceStat = _context.EvidenceStats.FirstOrDefault(x => x.Id == evidenceFormViewModel.Id); if (evidenceStat == null) { evidenceStat = new EvidenceStat() { StatDate = evidenceFormViewModel.StatDate, SubmitDate = DateTime.UtcNow, Quantity = evidenceFormViewModel.Quantity, Proceeds = evidenceFormViewModel.Proceeds }; _context.EvidenceStats.Add(evidenceStat); message = "Evidence added!"; } else { evidenceStat.StatDate = evidenceFormViewModel.StatDate; evidenceStat.SubmitDate = DateTime.UtcNow; evidenceStat.Quantity = evidenceFormViewModel.Quantity; evidenceStat.Proceeds = evidenceFormViewModel.Proceeds; } await _context.SaveChangesAsync(); message = "Evidence edited!"; return(new OkObjectResult(message)); }
public async Task <IActionResult> SetOrderStatus([FromBody] int statusId, int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var order = _context.Orders.FirstOrDefault(x => x.Id == id); order.Status = statusId; await _context.SaveChangesAsync(); return(new OkResult()); }
// [Authorize("Admin")] public async Task <IActionResult> EditProfile([FromBody] UserEditViewModel userEditViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var client = await _userManager.Users.Where(e => e.Id == userEditViewModel.Id).FirstOrDefaultAsync(); client.FirstName = userEditViewModel.FirstName; client.LastName = userEditViewModel.LastName; client.Email = userEditViewModel.Email; client.PhoneNumber = userEditViewModel.PhoneNumber; await _context.SaveChangesAsync(); return(new OkObjectResult(client)); }
public async Task <IActionResult> Post([FromBody] RegistrationViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userIdentity = _mapper.Map <Models.User>(model); var result = await _userManager.CreateAsync(userIdentity, model.Password); if (!result.Succeeded) { return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState))); } await _context.SaveChangesAsync(); return(new OkObjectResult("Account created")); }