public IActionResult cancel(int id) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } try { mtCompany item = mContext.mtCompany.Find(id); ICollection <mtCompanyDetails> items = mContext.mtCompanyDetails.Where(x => x.isActive == true && x.companyId == item.id).ToList(); mContext.Entry(item).Reload(); foreach (mtCompanyDetails value in items) { mContext.Entry(value).Reload(); } } catch (Exception e) { return(Ok(new { status = 409, message = e.Message })); } return(Ok(new { status = 200, message = "" })); }
public IActionResult Add([FromBody] mtCompany value) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } string user = HttpContext.Session.GetString("fullname"); DateTime txDate = DateTime.Now; if (value != null) { List <mtCompanyDetails> details = new List <mtCompanyDetails>(); foreach (mtCompanyDetails items in value.companyDetails) { items.isActive = true; items.createdBy = user; items.createdOn = txDate; items.updatedBy = user; items.updatedOn = txDate; } value.coaIdIdr = (value.coaIdIdr == 0 ? null : value.coaIdIdr); value.coaIdUsd = (value.coaIdUsd == 0 ? null : value.coaIdUsd); value.typeId = (value.typeId == 0 ? null : value.typeId); value.telepon = value.telepon.Replace("_", ""); value.taxNo = value.taxNo.Replace("_", ""); value.createdBy = user; value.createdOn = txDate; 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 (!isValid) { foreach (ValidationResult validationResult in results) { errorMessage.Add(validationResult.ErrorMessage); } return(Ok(new { status = 400, message = errorMessage })); } mContext.mtCompany.Add(value); mContext.SaveChanges(); return(Ok(new { status = 200, message = "" })); } return(Ok(new { status = 409, message = "Json is null, please Check Controller" })); }
public IActionResult IsActive(int id) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } mtCompany item = mContext.mtCompany.Find(id); item.isActive = !item.isActive; 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")); }