Beispiel #1
0
        public ActionResult Edit(PdtPlnViewModel model)
        {
            try
            {
                var item      = Mapper.Map <PdtPlnItem>(model);
                var isSuccess = _pdtPlnDomain.CreateOrUpdate(item);
                if (!isSuccess.IsSuccess)
                {
                    return(Json(new { Success = false, Message = isSuccess.ErrorMessages }, JsonRequestBehavior.AllowGet));
                }
                return(Json(
                           new { Success = true, Message = model.IsCreate ? MessageResource.MSG6 : MessageResource.MSG9 },
                           JsonRequestBehavior.AllowGet));

                ;
            }
            catch (DbUpdateException e)
            {
                var sb = new StringBuilder();
                sb.AppendLine("DbUpdateException error details - {e?.InnerException?.InnerException?.Message}");

                foreach (var eve in e.Entries)
                {
                    sb.AppendLine("Entity of type {eve.Entity.GetType().Name} in state {eve.State} could not be updated");
                }

                Console.WriteLine(sb.ToString());
                throw;
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public ActionResult Edit(string date, string preProdCode, int line)
        {
            var model = new PdtPlnViewModel
            {
                KndLine           = line,
                IsCreate          = true,
                F39_Status        = Constants.Status.Yet.ToString(),
                F39_KndEptBgnDate = DateTime.Now.ToString("dd/MM/yyyy")
            };

            if (!string.IsNullOrEmpty(preProdCode))
            {
                var entity = _pdtPlnDomain.GetById(ConvertHelper.ConvertToDateTimeFull(date), preProdCode);
                if (entity != null)
                {
                    model            = Mapper.Map <PdtPlnViewModel>(entity);
                    model.KndLine    = line;
                    model.F39_Status = Enum.GetName(typeof(Constants.Status), ConvertHelper.ToInteger(model.F39_Status));
                    model.IsCreate   = false;
                }
            }
            return(PartialView("PdtPln/_PartialViewEditPdtPln", model));
        }