public async Task <IHttpActionResult> CommentAbonentClaim(AbonentClaimCommentRequest model) { using (var context = new ApplicationDbContext()) { var userIdentityid = User.Identity.GetUserId <int>(); var abonents = context.Abonent.Where(x => x.ApplicationUser.Id == userIdentityid); if (!abonents.Any()) { return(NotFound()); } if (abonents.Count() > 1) { return(BadRequest()); } var abonent = abonents.Single(); var claimComment = new AbonentClaimComment { OrganizationId = abonent.OrganizationId, AbonentClaimId = model.AbonentClaimId, Comment = model.Comment, ChangedTime = DateTime.Now, CreationTime = DateTime.Now, InformationSource = EInformationSource.Abonent }; context.AbonentClaimComment.Add(claimComment); await context.SaveChangesAsync(); return(Ok()); } }
public async Task <ActionResult> CommentAbonentClaim(AbonentClaimComment abonentClaimViewModel, HttpPostedFileBase inputFile) { using (var context = new ApplicationDbContext()) { if (ModelState.IsValid) { var userIdentityid = User.Identity.GetUserId <int>(); var employee = await context.Employee.FirstOrDefaultAsync(x => x.ApplicationUser.Id == userIdentityid); if (employee == null) { throw new Exception("Не найден сотрудник"); } var claimComment = new AbonentClaimComment { OrganizationId = employee.OrganizationId, AbonentClaimId = abonentClaimViewModel.AbonentClaimId, Comment = abonentClaimViewModel.Comment, EmployeeId = employee.Id, ChangedTime = DateTime.Now, CreationTime = DateTime.Now, InformationSource = EInformationSource.Employee }; if (inputFile != null && inputFile.ContentLength > 0) { var fileStorageManager = OhConfigurator.Container.Resolve <IFileStorageManager>(); claimComment.ImportedFileId = (await fileStorageManager.SaveImportedFile(inputFile, userIdentityid, EImportType.AbonentFiles)) .Id; } context.AbonentClaimComment.Add(claimComment); await context.SaveChangesAsync(); } return(RedirectToAction("AbonentClaimEdit", new { id = abonentClaimViewModel.AbonentClaimId })); } }
public async Task <IHttpActionResult> CloseAbonentClaim(AbonentClaimCloseRequest model) { if (model.AbonentClaimId == default(long)) { return(BadRequest("Не задан идентификатор")); } using (var context = new ApplicationDbContext()) { var claim = await context.AbonentClaim.FindAsync(model.AbonentClaimId); if (claim == null) { return(NotFound()); } var userIdentityid = User.Identity.GetUserId <int>(); var abonents = context.Abonent.Where(x => x.ApplicationUser.Id == userIdentityid); if (!abonents.Any()) { return(NotFound()); } if (abonents.Count() > 1) { return(BadRequest()); } var abonent = abonents.Single(); if (claim.CreatorId != abonent.Id) { return(NotFound()); } claim.Rating = model.Rating; claim.Accepted = true; claim.CompleteDate = DateTime.Now; claim.ClaimStatus = EClaimStatus.Closed; await context.SaveChangesAsync(); var claimComment = new AbonentClaimComment { OrganizationId = abonent.OrganizationId, AbonentClaimId = model.AbonentClaimId, Comment = model.Comment, ChangedTime = DateTime.Now, CreationTime = DateTime.Now, InformationSource = EInformationSource.Abonent }; context.AbonentClaimComment.Add(claimComment); await context.SaveChangesAsync(); return(Ok()); } }