Ejemplo n.º 1
0
        public ApiMessage CreateStoreHouse()
        {
            ApiMessage message = new ApiMessage();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);

            try
            {
                BStoreHouse house = new BStoreHouse();
                house.Name=request["name"];
                house.Address=request["address"];
                house.Phone=request["phone"];
                house.IsDefault = false;
                if (!string.IsNullOrEmpty(request["isdefault"]))
                {
                    if (request["isdefault"] == "1")
                    {
                        house.IsDefault = true;
                    }
                }
                stockManager.CreateStoreHouse(house);
                message.Status = "ok";
                message.Message = "创建成功";
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "未知错误";
            }
            return message;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="house"></param>
        public void CreateStoreHouse(BStoreHouse house)
        {
            if (this.CurrentUserPermission.ADD_STORE_HOUSE == 0)
            {
                throw new KMJXCException("没有创建仓库的权限");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Store_House dbHouse = new Store_House();
                int existing = (from h in db.Store_House where house.Name.Contains(h.Title) select h).Count();
                if (existing > 0)
                {
                    throw new KMJXCException("类似的仓库名称已经存在");
                }

                dbHouse.Phone = house.Phone;
                dbHouse.Title = house.Name;
                dbHouse.Address = house.Address;
                dbHouse.Guard = 0;
                dbHouse.Create_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                dbHouse.User_ID = this.CurrentUser.ID;
                dbHouse.Default = house.IsDefault;
                dbHouse.Shop_ID = this.Shop.Shop_ID;
                if ((bool)dbHouse.Default)
                {
                    Store_House defaultHouse=(from hu in db.Store_House where hu.Default==true select hu).FirstOrDefault<Store_House>();
                    if (defaultHouse != null)
                    {
                        defaultHouse.Default = false;
                    }
                }
                db.Store_House.Add(dbHouse);
                db.SaveChanges();
                base.CreateActionLog(new BUserActionLog() { Shop = new BShop { ID = dbHouse.Shop_ID }, Action = new BUserAction() { Action_ID = UserLogAction.CREATE_STOREHOUSE }, Description = "" });
            }
        }