コード例 #1
0
        public ActionResult Create(Customer Customer, HttpPostedFileBase ImageFile)
        {
            if (ImageFile == null)
            {
                ModelState.AddModelError("Image", "Please upload an Image");
            }
            bool isValidFormate = common.ImageValidation(ImageFile);

            if (isValidFormate == false)
            {
                ModelState.AddModelError("Image", "only png,jpg,jpeg format is allowed");
            }

            byte[] ConvertedImage = common.ConvertImage(ImageFile);
            Customer.Image = ConvertedImage;
            if (ModelState.IsValid)
            {
                status = _customerBll.Create(Customer);
                if (status == true)
                {
                    return(RedirectToAction("List", "Customers"));
                }
                else
                {
                    ViewBag.Message = "Expense Catagory added failed";
                }
            }
            return(View(Customer));
        }
コード例 #2
0
        // POST api/customerapi
        public CCustomer Post(CCustomer value)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (
                var dal =
                    DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)
                )
            {
                bool ok;
                try
                {
                    dal.Open();
                    ok = CustomerBll.Create(dal, value, string.Format("{0}-{1}", user.UserCode, user.UserName));
                }
                catch (Exception ex)
                {
                    if (ex.Message.StartsWith("违反了 UNIQUE KEY 约束"))
                    {
                        throw new HttpResponseException(new PrimaryRepeatedMessge());
                    }
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "Customer.Post", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                if (!ok)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogContent = string.Format("新建客户{0}-{1}", value.CustomerCode, value.CustomerName),
                        LogType    = LogType.操作失败,
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName)
                    });
                    throw new HttpResponseException(new DealFailureMessage());
                }
                LogBll.Write(dal, new CLog
                {
                    LogContent = string.Format("新建客户{0}-{1}", value.CustomerCode, value.CustomerName),
                    LogType    = LogType.操作成功,
                    LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName)
                });
                dal.Close();
                return(value);
            }
        }