private async Task SaveImg(int code) { string idCheckBox = $"{code}-delete"; if (Request.Form[idCheckBox].FirstOrDefault() == null || Request.Form[idCheckBox].FirstOrDefault() == "false") { string idInput = $"{code}-file-upload-input"; IFormFile file = Request.Form.Files.FirstOrDefault(x => x.Name == idInput); if (file != null) { byte[] streamArray = new byte[file.Length]; await file.OpenReadStream().ReadAsync(streamArray, 0, streamArray.Length); MtdConfigFile imgConfig = new MtdConfigFile() { Id = code, Name = code == 1 ? "Image for menu" : "Image for AppBar", FileData = streamArray, FileSize = streamArray.Length, FileType = file.ContentType }; bool exists = await _context.MtdConfigFiles.Where(x => x.Id == code).AnyAsync(); if (exists) { _context.Attach(imgConfig).State = EntityState.Modified; } else { _context.Attach(imgConfig).State = EntityState.Added; } } } else { MtdConfigFile header = new MtdConfigFile() { Id = code }; _context.Attach(header).State = EntityState.Deleted; } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(MtdApproval).State = EntityState.Modified; _context.Entry(MtdApproval).Property(x => x.MtdForm).IsModified = false; await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } MtdForm oldForm = await _context.MtdForm.AsNoTracking().Include(x => x.ParentNavigation).FirstOrDefaultAsync(x => x.Id == MtdForm.Id); if (oldForm == null) { return(NotFound()); } MtdForm.Parent = oldForm.Parent; _context.Attach(MtdForm).State = EntityState.Modified; MtdForm.VisibleNumber = VisibleNumber ? (sbyte)1 : (sbyte)0; MtdForm.VisibleDate = VisibleDate ? (sbyte)1 : (sbyte)0; string idCheckBox = "header-delete"; if (Request.Form[idCheckBox].FirstOrDefault() == null || Request.Form[idCheckBox].FirstOrDefault() == "false") { string idInput = "header-file-upload-input"; IFormFile file = Request.Form.Files.FirstOrDefault(x => x.Name == idInput); if (file != null) { byte[] streamArray = new byte[file.Length]; await file.OpenReadStream().ReadAsync(streamArray, 0, streamArray.Length); MtdFormHeader header = new MtdFormHeader() { Id = MtdForm.Id, Image = streamArray, ImageSize = streamArray.Length, ImageType = file.ContentType }; bool exists = await _context.MtdFormHeader.Where(x => x.Id == MtdForm.Id).AnyAsync(); if (exists) { _context.Attach(header).State = EntityState.Modified; } else { _context.Attach(header).State = EntityState.Added; } } } else { MtdFormHeader header = new MtdFormHeader() { Id = MtdForm.Id }; _context.Attach(header).State = EntityState.Deleted; } string idCheckDeskBox = "desk-delete"; if (Request.Form[idCheckDeskBox].FirstOrDefault() == null || Request.Form[idCheckDeskBox].FirstOrDefault() == "false") { string idInput = "desk-file-upload-input"; IFormFile file = Request.Form.Files.FirstOrDefault(x => x.Name == idInput); if (file != null) { byte[] streamArray = new byte[file.Length]; await file.OpenReadStream().ReadAsync(streamArray, 0, streamArray.Length); MtdFormDesk desk = new MtdFormDesk() { Id = MtdForm.Id, Image = streamArray, ImageSize = streamArray.Length, ImageType = file.ContentType, ColorBack = "gray", ColorFont = "black" }; bool exists = await _context.MtdFormDesk.Where(x => x.Id == MtdForm.Id).AnyAsync(); if (exists) { _context.Attach(desk).State = EntityState.Modified; } else { _context.Attach(desk).State = EntityState.Added; } } } else { MtdFormDesk desk = new MtdFormDesk() { Id = MtdForm.Id }; _context.Attach(desk).State = EntityState.Deleted; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MtdFormExists(MtdForm.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostPartEditAsync() { string formId = Request.Form["formId"]; string partId = Request.Form["partId"]; string partName = Request.Form["partName"]; string partNote = Request.Form["partNote"]; string partStyle = Request.Form["partStyle"]; string partTitle = Request.Form["partTitle"]; string partChild = Request.Form["partChild"]; string partSeq = Request.Form["partSeq"]; int styleId = int.Parse(partStyle); int sequence = int.Parse(partSeq); bool titleCheck = bool.Parse(partTitle); bool childCheck = bool.Parse(partChild); MtdFormPart mtdFormPart = new MtdFormPart { Id = partId, Name = partName, Description = partNote, Active = true, MtdForm = formId, Title = titleCheck, Child = childCheck, MtdSysStyle = styleId, Sequence = sequence }; _context.MtdFormPart.Attach(mtdFormPart).State = EntityState.Modified; await _context.SaveChangesAsync(); _context.Attach(mtdFormPart).State = EntityState.Modified; string idCheckBox = "header-delete"; if (Request.Form[idCheckBox].FirstOrDefault() == null || Request.Form[idCheckBox].FirstOrDefault() == "false") { string idInput = "header-file-upload-input"; IFormFile file = Request.Form.Files.FirstOrDefault(x => x.Name == idInput); if (file != null) { byte[] streamArray = new byte[file.Length]; await file.OpenReadStream().ReadAsync(streamArray, 0, streamArray.Length); MtdFormPartHeader header = new MtdFormPartHeader() { Id = mtdFormPart.Id, Image = streamArray, ImageSize = streamArray.Length, ImageType = file.ContentType }; bool exists = await _context.MtdFormPartHeader.Where(x => x.Id == mtdFormPart.Id).AnyAsync(); if (exists) { _context.Attach(header).State = EntityState.Modified; } else { _context.Attach(header).State = EntityState.Added; } } } else { MtdFormPartHeader header = new MtdFormPartHeader() { Id = mtdFormPart.Id }; _context.Attach(header).State = EntityState.Deleted; } await _context.SaveChangesAsync(); return(Ok()); }