public async Task <IActionResult> PutWellMaintenanceWork(long id, WellMaintenanceWork wellMaintenanceWork) { if (id != wellMaintenanceWork.Id) { return(BadRequest()); } _context.Entry(wellMaintenanceWork).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WellMaintenanceWorkExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDrainPatrolAlarm(long id, DrainPatrolAlarm drainPatrolAlarm) { if (id != drainPatrolAlarm.Id) { return(BadRequest()); } _context.Entry(drainPatrolAlarm).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DrainPatrolAlarmExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <JsonResult> OnPostCreate([DataSourceRequest] DataSourceRequest request, RentalSchedularViewModel rental) { if (ModelState.IsValid) { // var device = await _context.RentalInventories.Where(a => a.Name == rental.Title).FirstOrDefault(); var insertData = new RentalReservation { PickupDate = rental.Start, ReturnDate = rental.End, RentalInventoryId = 1, // Id för Byggställning Description = rental.Description, AspNetUserId = User.Identity.Name }; await _context.RentalReservations.AddAsync(insertData); await _context.SaveChangesAsync(); rental.RentalId = insertData.Id; } return(new JsonResult(new[] { rental }.ToDataSourceResult(request, ModelState))); }
public async Task <IActionResult> PutPremise(long id, Premise premise) { if (id != premise.Id) { return(BadRequest()); } _context.Entry(premise).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PremiseExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutActivityPerRow(long id, ActivityPerRow activityPerRow) { if (id != activityPerRow.Id) { return(BadRequest()); } _context.Entry(activityPerRow).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActivityPerRowExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Activity> > PostDrainPatrol(ActivityViewModel drainPatrolViewModel) { var insertData = new Activity { Master_node = drainPatrolViewModel.Master_node, Index = drainPatrolViewModel.Index, Address = drainPatrolViewModel.Address, Time = drainPatrolViewModel.Time, Active = drainPatrolViewModel.Active }; // SignalR to update page with above record await _hub.Clients.All.SendAsync("DrainActivity", insertData.Address, insertData); // Save data in Azure Table Storage to flatten out the data. await SaveToTableStorage(drainPatrolViewModel); // Save activity in Azure SQL to table Activities _context.Activities.Add(insertData); await _context.SaveChangesAsync(); // Email if A or B-Alarm switch (insertData.Address) { case "2O1": await SendEmailAlarm(insertData, "A-larm"); break; case "2O2": await SendEmailAlarm(insertData, "B-larm"); break; default: if (insertData.Address.StartsWith("3") && insertData.Address.EndsWith("8")) { await SendEmailWellFull(insertData); } break; } return(Ok(drainPatrolViewModel)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Contact.UpdatedAt = System.DateTime.Now; _context.Attach(Contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(Contact.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./MemberIndex")); }
public async Task <IActionResult> OnPost() { if (!ModelState.IsValid) { return(Page()); } var user = await GetUser(); // Check if logged in user tries to save more than one survey var isAnswered = _context.SurveyAnswereds.AnyAsync(a => a.UserName == user.UserName && a.SurveyName == "Investeringar"); if (isAnswered.Result) { return(RedirectToPage("SurveyAnswered")); } SurveyAnswered sa = new SurveyAnswered { UserName = user.UserName, SurveyName = "Investeringar" }; _context.SurveyAnswereds.Add(sa); await _context.SaveChangesAsync(); Survey survey = new Survey { SurveyName = "Investeringar", Query1 = SurveyViewModel.Query1, Query2 = SurveyViewModel.Query2, Query3 = SurveyViewModel.Query3, //Query4 = SurveyViewModel.Query4, //Query5 = SurveyViewModel.Query5, }; _context.Surveys.Add(survey); await _context.SaveChangesAsync(); return(RedirectToPage("SurveyThanks")); }
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> OnPostAsync(long?id) { var member = await _context.PremiseContacts.FindAsync(id); if (member != null) { member.IsDeleted = true; _context.Attach(member).State = EntityState.Modified; await _context.SaveChangesAsync(); } return(RedirectToPage("./ProfileIndex")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Contact.IsActive = true; Contact.IsDeleted = false; Contact.CreatedAt = System.DateTime.Now; Contact.UpdatedAt = System.DateTime.Now; _context.PremiseContacts.Add(Contact); await _context.SaveChangesAsync(); return(RedirectToPage("./ProfileIndex")); }
public async Task <TwiMLResult> ReceiveSms([FromForm] SmsRequest incomingMessage) { var sms = new IncommingSms { To = incomingMessage.To, From = incomingMessage.From, Message = incomingMessage.Body, CreatedAt = System.DateTime.Now }; await _context.IncommingSms.AddAsync(sms); await _context.SaveChangesAsync(); var messagingResponse = new MessagingResponse(); messagingResponse.Message($"Tack för din kommentar!"); return(TwiML(messagingResponse)); }
public async Task <JsonResult> OnPostUpload(string path, IFormFile file) { if (file != null) { var fileContent = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(file.ContentDisposition); var fileName = System.IO.Path.GetFileName(fileContent.FileName.ToString().Trim('"')); var filePath = Path.GetTempFileName(); var directory = await _context.UploadFileDirectories .Where(a => a.Directory == path) .FirstOrDefaultAsync(); long size = file.Length; // await UploadFileBlobAsync(filePath, fileName); string result = await UploadFile(file, filePath); if (result == "OK") { var user = await _userManager.GetUserAsync(HttpContext.User); var fileExit = await _context.UploadedFiles.Where(o => o.FileName == fileName && o.Directory == path && o.Container == MyConsts.boardDocuments).FirstOrDefaultAsync(); if (fileExit != null) { fileExit.UpdatedAt = DateTime.Now; fileExit.AspNetUserId = user.Id; _context.UploadedFiles.Add(fileExit); _context.Entry(fileExit).State = EntityState.Modified; await _context.SaveChangesAsync(); } else { var insertData = new UploadedFile { FileName = fileName, Path = directory.Directory + "/" + fileName, Size = size, Directory = directory.Directory, Container = MyConsts.boardDocuments, UploadFileDirectoryId = directory.Id, UploadFileCategoryId = directory.UploadFileCategoryId, HasDirectories = false, IsDirectory = false, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, AspNetUserId = user.Id }; _context.UploadedFiles.Add(insertData); await _context.SaveChangesAsync(); } } Message = fileName + " är nu sparad."; } var lovaDirectories = await _context.UploadFileDirectories .Where(a => a.UploadFileCategoryId == 2 && string.IsNullOrEmpty(path)?a.Directory != path : a.Directory == "apa") .Select(a => new ViewFilesViewModel { Name = a.Directory, Path = a.Directory, Size = 0, Created = DateTime.Now, CreatedUtc = DateTime.Now, Modified = DateTime.Now, ModifiedUtc = DateTime.Now, HasDirectories = false, IsDirectory = true, Extension = "" }) .ToArrayAsync(); var lovaFiles = await _context.UploadedFiles .Where(a => a.UploadFileCategoryId == 2 && a.IsDirectory == false && a.Directory == path) .Select(a => new ViewFilesViewModel { Name = Path.GetFileNameWithoutExtension(a.FileName), Path = a.Path, Size = a.Size, Created = a.CreatedAt, CreatedUtc = a.CreatedAt, Modified = a.UpdatedAt, ModifiedUtc = a.UpdatedAt, HasDirectories = a.HasDirectories, IsDirectory = a.IsDirectory, Extension = Path.GetExtension(a.FileName) }) .ToArrayAsync(); var files = lovaDirectories.Concat(lovaFiles); return(new JsonResult(files)); }
public async Task OnPost(IFormFile files) { if (files != null) { var fileContent = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(files.ContentDisposition); var fileName = System.IO.Path.GetFileName(fileContent.FileName.ToString().Trim('"')); var filePath = Path.GetTempFileName(); var directory = await _context.UploadFileDirectories .Where(a => a.Id == FileUpload.UploadFileDirectoryId) .FirstOrDefaultAsync(); long size = files.Length; // await UploadFileBlobAsync(filePath, fileName); // string container = FileUpload.UploadFileCategoryId == 1 ? MyConsts.lovaDocuments : MyConsts.lottingelundDocuments; string container = ""; switch (FileUpload.UploadFileCategoryId) { case 1: container = MyConsts.lovaDocuments; break; case 2: container = MyConsts.boardDocuments; break; default: container = MyConsts.lottingelundDocuments; break; } string result = await UploadFile(files, filePath, container); if (result == "OK") { var user = await _userManager.GetUserAsync(HttpContext.User); var fileExit = await _context.UploadedFiles.Where(o => o.FileName == fileName && o.Directory == directory.Directory && o.Container == container).FirstOrDefaultAsync(); if (fileExit != null) { fileExit.UpdatedAt = DateTime.Now; fileExit.AspNetUserId = user.Id; _context.UploadedFiles.Add(fileExit); _context.Entry(fileExit).State = EntityState.Modified; await _context.SaveChangesAsync(); } else { var insertData = new UploadedFile { FileName = fileName, Path = directory.Directory + "/" + fileName, Size = size, Directory = directory.Directory, UploadFileDirectoryId = FileUpload.UploadFileDirectoryId, UploadFileCategoryId = FileUpload.UploadFileCategoryId, Container = container, HasDirectories = false, IsDirectory = false, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, AspNetUserId = user.Id }; _context.UploadedFiles.Add(insertData); await _context.SaveChangesAsync(); } } Message = fileName + " är nu sparad."; } }
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")); }