コード例 #1
0
        public JsonResult SaveAllEntity(SanphamViewModel sanphamVm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                    return(Json(allErrors, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var user = UserLoginViewModel.Current;
                    var ncc  = _userService.GetUser(user.KeyId);
                    ncc.NccNavigation.sltinton -= 1;
                    sanphamVm.mancc             = user.KeyId;
                    _sanphamService.Add(sanphamVm);
                }
                if (_sanphamService.Save())
                {
                    return(Json(new { Result = sanphamVm, Status = "OK" }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { Result = "", Status = "FAIL" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Result = ex.Message, Status = "FAIL" }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public JsonResult SaveEntity(SanphamViewModel sanphamVm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                    return(Json(allErrors, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    if (sanphamVm.KeyId == 0)
                    {
                        _sanphamService.Add(sanphamVm);
                    }
                    else
                    {
                        _sanphamService.Update(sanphamVm);
                    }
                }
                if (_sanphamService.Save())
                {
                    return(Json(sanphamVm, JsonRequestBehavior.AllowGet));
                }

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(Response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        public SanphamViewModel Add(SanphamViewModel sanphamVm)
        {
            var sp = Mapper.Map <SanphamViewModel, Sanpham>(sanphamVm);

            _repository.AddReturn(sp);
            sp.masp         = sp.KeyId.ToString();
            sanphamVm.KeyId = sp.KeyId;
            sanphamVm.masp  = sp.masp;
            //sanphamVm.Id = _convertFunction.Instance.Create_Code(true, sp.KeyId,
            //CommonConstants.defaultLengthNumberCode, const_AddressbookType.Employee);
            //sp.Id = HP_EmployeeVm.Id;
            //employee.UserBy.IsEmployee = true;
            return(sanphamVm);
        }
コード例 #4
0
        public void Update(SanphamViewModel sanphamVm)
        {
            var sp = Mapper.Map <SanphamViewModel, Sanpham>(sanphamVm);

            _repository.Update(sp);
        }