public async Task <IActionResult> OnPostAsync() { var user = await GetUser(); foreach (var item in MailSubscriptions) { if (item.MailSubscriptionId == 0) { var ms = new MailSubscription { Email = user.UserName, MailTypeId = item.MailTypeId, Name = "" }; await _context.AddAsync(ms); await _context.SaveChangesAsync(); } else { var ms = new MailSubscription { Id = item.MailSubscriptionId, Email = user.UserName, MailTypeId = item.MailTypeId, Name = "", IsScription = item.IsScription }; _context.Attach(ms).State = EntityState.Modified; await _context.SaveChangesAsync(); } } ; return(RedirectToPage()); }
public async Task <ActionResult <IssueReport> > PostIssueReport(IssueReportViewModel issueReport) { var well = await _context.Wells.Where(a => a.WellName == issueReport.WellName).FirstOrDefaultAsync(); var insertData = new IssueReport { WellId = well.Id, ProblemDescription = issueReport.ProblemDescription, SolutionDescription = issueReport.SolutionDescription, NewActivatorSerialNumber = issueReport.NewActivatorSerialNumber, NewValveSerialNumber = issueReport.NewValveSerialNumber, IsChargeable = issueReport.IsChargeable, Photo = issueReport.ImageName, OldActivatorSerialNumber = well.ActivatorSerialNumber, OldValveSerialNumber = well.ValveSerialNumber, TimeForAlarm = issueReport.TimeForAlarm, ArrivalTime = issueReport.ArrivalTime, TimeToRepair = issueReport.TimeToRepair, CreatedAt = issueReport.CreatedAt, UpdatedAt = issueReport.CreatedAt }; well.ActivatorSerialNumber = string.IsNullOrEmpty(issueReport.NewActivatorSerialNumber) ? well.ActivatorSerialNumber : issueReport.NewActivatorSerialNumber; well.ValveSerialNumber = string.IsNullOrEmpty(issueReport.NewValveSerialNumber) ? well.ValveSerialNumber : issueReport.NewValveSerialNumber; well.UpdatedAt = DateTime.UtcNow; await _context.AddAsync(well); _context.Entry(well).State = EntityState.Modified; await _context.SaveChangesAsync(); _context.IssueReports.Add(insertData); await _context.SaveChangesAsync(); // return CreatedAtAction("GetIssueReport", new { id = issueReport.Id }, issueReport); return(Ok(issueReport)); }
public async Task <IActionResult> OnPost() { if (!ModelState.IsValid) { return(Page()); } var well = await _context.Wells.Where(a => a.WellName == IssueReportViewModel.WellName).FirstOrDefaultAsync(); if (well == null) { } var user = await _userManager.GetUserAsync(HttpContext.User); var fileName = ""; if (IssueReportViewModel.File != null) { var fileContent = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(IssueReportViewModel.File.ContentDisposition); fileName = Path.GetFileName(fileContent.FileName.ToString().Trim('"')); var filePath = Path.GetTempFileName(); string result = await UploadFile(IssueReportViewModel.File, filePath); } IssueReport insertData = new IssueReport { WellId = well.Id, ProblemDescription = IssueReportViewModel.ProblemDescription, SolutionDescription = IssueReportViewModel.SolutionDescription, NewActivatorSerialNumber = IssueReportViewModel.NewActivatorSerialNumber, NewValveSerialNumber = IssueReportViewModel.NewValveSerialNumber, OldActivatorSerialNumber = well.ActivatorSerialNumber, OldValveSerialNumber = well.ValveSerialNumber, IsChargeable = IssueReportViewModel.IsChargeable, IsPhoto = IssueReportViewModel.IsPhoto, IsLowVacuum = IssueReportViewModel.IsLowVacuum, MasterNode = IssueReportViewModel.MasterNode + 1, Photo = fileName, Alarm = IssueReportViewModel.Alarm + 1, TimeForAlarm = IssueReportViewModel.TimeForAlarm, ArrivalTime = IssueReportViewModel.ArrivalTime, TimeToRepair = IssueReportViewModel.TimeToRepair, AspNetUserId = user.Id, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow }; well.ActivatorSerialNumber = string.IsNullOrEmpty(IssueReportViewModel.NewActivatorSerialNumber) ? well.ActivatorSerialNumber : IssueReportViewModel.NewActivatorSerialNumber; well.ValveSerialNumber = string.IsNullOrEmpty(IssueReportViewModel.NewValveSerialNumber) ? well.ValveSerialNumber : IssueReportViewModel.NewValveSerialNumber; well.UpdatedAt = DateTime.UtcNow; await _context.AddAsync(well); _context.Entry(well).State = EntityState.Modified; await _context.SaveChangesAsync(); _context.IssueReports.Add(insertData); await _context.SaveChangesAsync(); return(RedirectToPage("WaterDrainReport")); }