Beispiel #1
0
 public Result Update(ProdDto dto)
 {
     try
     {
         var entity = dto.MapTo <ProdEntity>();
         var rlt    = UnitOfWorkService.Execute(() => _prodRepository.Update(entity));
         if (!rlt)
         {
             return new Result {
                        Status = false, Message = "数据库操作失败"
             }
         }
         ;
         return(new Result {
             Status = true
         });
     }
     catch (Exception ex)
     {
         Logger.Error("update prod error:", ex);
         return(new Result {
             Status = false, Message = "内部服务器错误"
         });
     }
 }
        public JsonResult UpdateProduct(int productID, object json)
        {
            ProductModel prodModel = new ProductModel(json.ToString());

            LoginData.ConnectionString =
                ConfigurationManager.ConnectionStrings["PXLDB"].ConnectionString;
            LoginData.LoginSuccessFul = true;
            ProductBusiness pb      = new ProductBusiness();
            ProdDto         product = new ProdDto();

            product.Price        = prodModel.price;
            product.Productname  = prodModel.productName;
            product.Description  = prodModel.description;
            product.category     = prodModel.category;
            product.productImage = prodModel.productimage;

            JsonResult json2      = new JsonResult();
            bool       validation = false;

            pb.UpdateProduct(product, productID);
            validation = true;

            json2.Data = validation;

            return(json2);
        }
Beispiel #3
0
        public void UpdateProduct(ProdDto prodDto, int primaryKeyValue)
        {
            prodDto.Creationid   = LoginData.UserID;
            prodDto.CreationDate = DateTime.Now;
            ProdData prodData = new ProdData(prodDto);

            prodData.UpdateRecord(primaryKeyValue);
            LoginData.Stop();
        }
Beispiel #4
0
        public void CreateProduct(ProdDto prodDto)
        {
            prodDto.Creationid   = LoginData.UserID;
            prodDto.CreationDate = DateTime.Now;
            ProdData prodData = new ProdData(prodDto);

            prodDto.Productid = prodData.CreateRecord();
            LoginData.Stop();
        }
Beispiel #5
0
 public IActionResult Modify(string opt, string id)
 {
     try
     {
         ViewBag.opt = opt;
         ViewBag.id  = id;
         var model = new ProdDto();
         if (!id.Equals("0"))
         {
             model = _prodService.Get(id);
         }
         return(View(model));
     }
     catch (Exception ex)
     {
         Logger.Error("prod错误", ex);
         return(View(new ProdDto()));
     }
 }
        public JsonResult GetProductById(int productId)
        {
            LoginData.ConnectionString =
                ConfigurationManager.ConnectionStrings["PXLDB"].ConnectionString;
            LoginData.LoginSuccessFul = true;
            ProductBusiness pb         = new ProductBusiness();
            ProdDto         dt         = pb.GetProdDto(productId);
            JsonResult      json       = new JsonResult();
            string          jsonString = JsonConvert.SerializeObject(dt);

            json.Data = jsonString;
            json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            if (string.Equals(json.Data, "[]"))
            {
                json.Data = false;
            }

            return(json);
        }
Beispiel #7
0
        public Result Add(ProdDto dto, UserType roleId)
        {
            try
            {
                var id     = "";
                var entity = dto.MapTo <ProdEntity>();
                var rlt    = UnitOfWorkService.Execute(() =>
                {
                    id            = _prodRepository.InsertAndGetId(entity);
                    var orgId     = _staffRepository.GetOrgId(dto.SalesMan).OrgId;
                    var dataInOrg = new DataInOrgEntity
                    {
                        DataId   = id,
                        DataType = (int)DataType.Prod,
                        OrgId    = orgId,
                        RoleId   = ((int)roleId).ToString()
                    };
                    var dataRlt = _dataInOrgRepository.Inserts(dataInOrg);

                    return(id.IsNotNullOrEmpty() && dataRlt);
                });
                if (!rlt)
                {
                    return new Result {
                               Status = false, Message = "数据库操作失败"
                    }
                }
                ;
                return(new Result {
                    Status = true
                });
            }
            catch (Exception ex)
            {
                Logger.Error("add prod error:", ex);
                return(new Result {
                    Status = false, Message = "内部服务器错误"
                });
            }
        }
Beispiel #8
0
 public async Task <Result> Modify(ProdDto dto, string opt)
 {
     try
     {
         var salesMan = "";
         if (dto.UserId.IsNotNullOrEmpty())
         {
             salesMan = _customerService.Get(dto.UserId).SalesMan;
         }
         else
         {
             salesMan = null;
         }
         var total = Math.Ceiling(dto.Money / dto.Price) + dto.Value;
         return(await Task.Run(() =>
         {
             dto.CreateDate = DateTime.Now;
             dto.CreatorId = LoginInfo.Id;
             dto.Total = decimal.ToInt32(total);            //decimal.ToInt32(dto.Money / dto.Price) + dto.Value;
             if (opt == "add")                              //新增
             {
                 dto.Id = DateTime.Now.ToStringTimeStamp(); // Guid.NewGuid().ToString();
                 dto.SalesMan = salesMan;                   //从客户表获取
                 return _prodService.Add(dto, LoginInfo.Role);
             }
             //修改
             return _prodService.Update(dto);
         }));
     }
     catch (Exception e)
     {
         Logger.Error("新增错误", e);
         return(new Result {
             Status = false
         });
     }
 }