Ejemplo n.º 1
0
        //
        // GET: /ZPVM/PowersetDetail/Modify
        public async Task <ActionResult> Modify(string code, int itemNo, string subCode)
        {
            PowersetDetailViewModel viewModel = new PowersetDetailViewModel();

            using (PowersetDetailServiceClient client = new PowersetDetailServiceClient())
            {
                MethodReturnResult <PowersetDetail> result = await client.GetAsync(new PowersetDetailKey()
                {
                    Code    = code,
                    ItemNo  = itemNo,
                    SubCode = subCode
                });

                if (result.Code == 0)
                {
                    viewModel = new PowersetDetailViewModel()
                    {
                        Code       = result.Data.Key.Code,
                        ItemNo     = result.Data.Key.ItemNo,
                        SubCode    = result.Data.Key.SubCode,
                        SubName    = result.Data.SubName,
                        MaxValue   = result.Data.MaxValue,
                        MinValue   = result.Data.MinValue,
                        IsUsed     = result.Data.IsUsed,
                        CreateTime = result.Data.CreateTime,
                        Creator    = result.Data.Creator,
                        Editor     = result.Data.Editor,
                        EditTime   = result.Data.EditTime
                    };
                    return(PartialView("_ModifyPartial", viewModel));
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                }
            }
            return(PartialView("_ModifyPartial"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> SaveModify(PowersetDetailViewModel model)
        {
            MethodReturnResult rst = new MethodReturnResult();

            if (model.Picture != null && !model.Picture.ContentType.Contains("image"))
            {
                rst.Code    = 1000;
                rst.Message = string.Format(StringResource.ValidateImageFileFormat, ZPVMResources.StringResource.PowersetDetailViewModel_Picture);
                return(Json(rst));
            }
            if (model.Picture.ContentLength > 6000)
            {
                rst.Code    = 1000;
                rst.Message = "上传图片较大,请重新确认图片大小!";
                return(Json(rst));
            }
            try
            {
                using (PowersetDetailServiceClient client = new PowersetDetailServiceClient())
                {
                    PowersetDetailKey key = new PowersetDetailKey()
                    {
                        Code    = model.Code,
                        ItemNo  = model.ItemNo,
                        SubCode = model.SubCode
                    };
                    MethodReturnResult <PowersetDetail> result = await client.GetAsync(key);

                    if (result.Code == 0)
                    {
                        result.Data.MaxValue = model.MaxValue;
                        result.Data.MinValue = model.MinValue;
                        result.Data.SubName  = model.SubName;
                        result.Data.IsUsed   = model.IsUsed;
                        result.Data.Editor   = User.Identity.Name;
                        result.Data.EditTime = DateTime.Now;

                        if (model.IsDeletePicture)
                        {
                            result.Data.Picture = null;
                        }
                        else if (model.Picture != null && model.Picture.ContentLength > 10)
                        {
                            int length = (int)model.Picture.InputStream.Length;
                            result.Data.Picture = new byte[length];
                            model.Picture.InputStream.Read(result.Data.Picture, 0, length);
                        }

                        rst = await client.ModifyAsync(result.Data);

                        if (rst.Code == 0)
                        {
                            rst.Message += string.Format(ZPVMResources.StringResource.PowersetDetail_SaveModify_Success
                                                         , model.Code);
                        }

                        return(Json(rst));
                    }
                    return(Json(result));
                }
            }
            catch (Exception ex)
            {
                rst.Code    = 1000;
                rst.Message = ex.Message;
                rst.Detail  = ex.ToString();
            }
            return(Json(rst));
        }