public IActionResult Add([FromBody] trSellingShipper value) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } string user = HttpContext.Session.GetString("fullname"); DateTime txDate = DateTime.Now; SystemDocumentNo sysDocNo = new SystemDocumentNo(mContext); try{ value.referenceNo = (value.id == 0 ? sysDocNo.getDocNo("SellingShipper", "RefNo", false) : value.referenceNo); value.isActive = true; value.createdBy = (value.id == 0 ? user : value.createdBy); value.createdOn = (value.id == 0 ? txDate : value.createdOn); value.updatedBy = user; value.updatedOn = txDate; var context = new ValidationContext(value, serviceProvider: null, items: null); var results = new List <ValidationResult>(); var isValid = Validator.TryValidateObject(value, context, results, true); List <string> errorMessage = new List <string>(); if (value.shipperId == 0) { errorMessage.Add("To harus di isi"); } if (value.employeeId == 0) { errorMessage.Add("From harus di isi"); } if (value.portOfLoadingId == 0) { errorMessage.Add("Port Of Loading harus di isi"); } if ((!isValid) || (errorMessage.Count > 0)) { foreach (ValidationResult validationResult in results) { errorMessage.Add(validationResult.ErrorMessage); } return(Ok(new { status = 400, message = errorMessage })); } if (value.id == 0) { value.referenceNo = (value.id == 0 ? sysDocNo.getDocNo("SellingShipper", "RefNo", true) : ""); mContext.trSellingShipper.Add(value); } else { mContext.Entry(value).State = EntityState.Modified; } mContext.SaveChanges(); return(Ok(new { status = 200, message = new { id = value.id, referenceNo = value.referenceNo } })); } catch (Exception ex) { return(Ok(new { status = 409, message = ex.Message })); } }
public IActionResult Edit(mtEmployee item, IFormFile pictureUrl) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } SystemDocumentNo sysDocNo = new SystemDocumentNo(mContext); if (pictureUrl == null || pictureUrl.Length == 0) { item.pictureUrl = item.pictureUrl; } else { string fileName = sysDocNo.getDocNo("Employee", "Image", true) + Path.GetExtension(pictureUrl.FileName); string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/employeeImages", fileName); pictureUrl.CopyTo(new FileStream(path, FileMode.Create)); item.pictureUrl = fileName; } if (ModelState.IsValid) { string user = HttpContext.Session.GetString("fullname"); DateTime txDate = DateTime.Now; item.updatedBy = user; item.updatedOn = txDate; mContext.Entry(item).State = EntityState.Modified; mContext.SaveChanges(); return(RedirectToAction("Index")); } if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } ICollection <sysModule> moduleLvl1 = mContext.sysModuleRole.Include(x => x.module) .Where(x => x.userRoleId == HttpContext.Session.GetInt32("roleId") && x.isActive == true && x.module.level == 1) .Select(x => x.module).ToList(); ICollection <sysModule> moduleLvl2 = mContext.sysModuleRole.Include(x => x.module) .Where(x => x.userRoleId == HttpContext.Session.GetInt32("roleId") && x.isActive == true && x.module.level == 2) .Select(x => x.module).ToList(); ViewBag.moduleLvl1 = moduleLvl1.OrderBy(x => x.orderModule); ViewBag.moduleLvl2 = moduleLvl2.OrderBy(x => x.orderModule); ViewBag.user = HttpContext.Session.GetString("fullname"); try { sysModule menu2 = moduleLvl2.Where(x => x.code == "Employee").SingleOrDefault(); sysModule menu1 = moduleLvl1.Where(x => x.id == menu2.parentId).SingleOrDefault(); ViewData["Menu"] = menu1.name; ViewData["SubMenuLvl1"] = menu2.name; ViewData["Title"] = menu2.name; } catch { return(RedirectToAction("index", "login")); } ViewBag.Error = true; return(View("edit")); }