Exemplo n.º 1
0
        public static ReturnJasonConstruct <DTO.Address> Create(DTO.Address dto)
        {
            ReturnJasonConstruct <DTO.Address> obj = new ReturnJasonConstruct <DTO.Address>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                if (db.Addresses.Count(p => p.accountId == dto.accountId) == maxAddressCount)
                {
                    obj.SetWarningInformation("您的地址数不能超过6个,请删除其他地址来添加地址信息");
                    return(obj);
                }
                if (dto.defaultAddress == true)//Need set other address to undefault
                {
                    StaticSetAddressUndefault(ref db, dto.accountId);
                }

                Models.Address model = dto.ToModel();
                model.id = Guid.NewGuid();
                db.Addresses.Add(model);
                db.SaveChanges();
                obj.SetDTOObject(model.ToDTO());
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
            return(obj);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Send message to cellphone by indicate
 /// </summary>
 /// <param name="telNo">cellphone number</param>
 /// <returns>   0,can send cert code;
 ///             1:exist;
 ///             2,wait 1 minutes;
 /// </returns>
 static public int CanSendCheckCode(string telNo)
 {
     try
     {
         MissFreshEntities db = new MissFreshEntities();
         var result           = db.Accounts.AsQueryable().Where(p => p.Customer.telNo == telNo && p.Customer.password != null).SingleOrDefault();
         if (result != null)
         {
             return(1);
         }
         else
         {
             result = db.Accounts.AsQueryable().Where(p => p.Customer.telNo == telNo && p.Customer.password == null).SingleOrDefault();
             if (result == null)
             {
                 return(0);
             }
             else
             {
                 if (result.codeTime == null || (DateTime.Now - result.codeTime).Value.Minutes > 1)
                 {
                     return(0);
                 }
                 else
                 {
                     return(2);//This branch means user send SMS interval less than 1min.
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Update account information
        /// </summary>
        /// <param name="telNo"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ReturnJasonConstruct <DTO.Account> Update(string telNo, int code)
        {
            ReturnJasonConstruct <DTO.Account> obj = new ReturnJasonConstruct <DTO.Account>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var model            = db.Accounts.SingleOrDefault(p => p.Customer.telNo == telNo);
                if (model == null)
                {
                    obj.status      = (int)executeStatus.warning;
                    obj.information = "创建用户失败.";
                    return(obj);
                }
                else
                {
                    model.code = code.ToString();
                    db.SaveChanges();

                    obj.SetDTOObject(model.ToDTO());
                    obj.status    = (int)executeStatus.success;
                    obj.DTOObject = model.ToDTO();
                    return(obj);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
        public static ReturnJasonConstruct <bool> DeleteAddressConfig(Guid id)
        {
            ReturnJasonConstruct <bool> obj = new ReturnJasonConstruct <bool>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var addressConfig    = db.AddressConfigs.SingleOrDefault(p => p.id == id);
                if (addressConfig == null)
                {
                    obj.SetWarningInformation("无法查找到对应的地址信息.");
                    return(obj);
                }
                db.AddressConfigs.Remove(addressConfig);
                db.SaveChanges();
                obj.SetDTOObject(true);

                return(obj);
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, false);
                return(obj);
            }
        }
Exemplo n.º 5
0
        static public ReturnJasonConstruct <DTO.Meals> GetEntireMeals(Guid mealsId)
        {
            ReturnJasonConstruct <DTO.Meals> list = new ReturnJasonConstruct <DTO.Meals>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var meals            = db.Meals.SingleOrDefault(p => p.id == mealsId);
                var goodsListQuery   = from r in db.MealsDetails
                                       join g in db.Goods
                                       on r.goodsId equals g.id
                                       where r.mealsId == mealsId
                                       select g;
                var goodsList = goodsListQuery.ToList();
                var DTOobject = meals.ToDTO();
                DTOobject.goodsList = goodsList.ToDTOs();
                list.SetDTOObject(DTOobject);
                return(list);
            }
            catch (Exception ex)
            {
                list.SetFailedInformation(ex.Message, null);
                return(list);
            }
        }
Exemplo n.º 6
0
        public static ReturnJasonConstruct <DTO.EntireMealsOrder> GetEntireOrderInformation(Guid id, Guid accId)
        {
            ReturnJasonConstruct <DTO.EntireMealsOrder> list = new ReturnJasonConstruct <DTO.EntireMealsOrder>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var order            = db.MealsOrders.SingleOrDefault(p => p.id == id);
                var dto  = order.ToEntireMealsOrder();
                var temp = from r in db.MealsOrderDetails.Where(p => p.mealsOrderId == id)
                           join m in db.Meals.AsQueryable <Models.Meal>()
                           on r.mealsId equals m.id
                           select r;
                foreach (var item in temp.ToList())
                {
                    var subdto = item.ToDTO();
                    subdto.name = item.Meal.name;
                    dto.orderDetail.Add(subdto);
                }
                list.SetDTOObject(dto);
                return(list);
            }
            catch (Exception ex)
            {
                list.SetFailedInformation(ex.Message, null);
                return(list);
            }
        }
Exemplo n.º 7
0
        public static ReturnJasonConstruct <DTO.Order> UpdateOrderStatus(Guid id)
        {
            ReturnJasonConstruct <DTO.Order> DTOObject = new ReturnJasonConstruct <DTO.Order>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var order            = db.Orders.SingleOrDefault(p => p.id == id);
                if (order.orderState == (int)orderStatus.Created)
                {
                    DTOObject.SetWarningInformation("当前订单没有支付,无法改变状态.");
                    return(DTOObject);
                }
                if (order.orderState == (int)orderStatus.complete || order.orderState == (int)orderStatus.close)
                {
                    DTOObject.SetWarningInformation("当前订单为结束或者关闭状态,无法改变状态.");
                    return(DTOObject);
                }
                order.orderState += 1;
                db.SaveChanges();
                DTOObject.SetDTOObject(order.ToDTO());
                return(DTOObject);
            }
            catch (Exception ex)
            {
                DTOObject.SetFailedInformation(ex.Message, null);
                return(DTOObject);
            }
        }
Exemplo n.º 8
0
        public static ReturnJasonConstruct <DTO.Address> Update(DTO.Address dto)
        {
            ReturnJasonConstruct <DTO.Address> obj = new ReturnJasonConstruct <DTO.Address>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                if (dto.defaultAddress == true)//Need set other address to undefault
                {
                    StaticSetAddressUndefault(ref db, dto.accountId);
                }

                var model = db.Addresses.Single(p => p.id == dto.id);
                model.Address1       = dto.Address1;
                model.tel            = dto.tel;
                model.name           = dto.name;
                model.defaultAddress = dto.defaultAddress;
                db.SaveChanges();

                obj.SetDTOObject(model.ToDTO());
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
            return(obj);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Save check code result for create user
        /// </summary>
        /// <param name=""></param>
        static public ReturnJasonConstruct <DTO.Account> Create(string telNo, int code)
        {
            ReturnJasonConstruct <DTO.Account> obj = new ReturnJasonConstruct <DTO.Account>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();

                Models.Customer ct = new Models.Customer();
                ct.id         = Guid.NewGuid();
                ct.telNo      = telNo;
                ct.createTime = DateTime.Now;

                Models.Account ac = new Models.Account();
                ac.id     = Guid.NewGuid();
                ac.code   = code.ToString();
                ac.userId = ct.id;

                db.Customers.Add(ct);
                db.Accounts.Add(ac);
                db.SaveChanges();

                obj.status    = (int)executeStatus.success;
                obj.DTOObject = ac.ToDTO();

                return(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 10
0
        public static ReturnJasonConstruct <IList <DTO.Order> > GetAllOrders(Guid id)
        {
            ReturnJasonConstruct <IList <DTO.Order> > list = new ReturnJasonConstruct <IList <DTO.Order> >();

            try
            {
                MissFreshEntities db  = new MissFreshEntities();
                string            str = @"select o.id as orderId,o.orderNo as orderNo,o.orderState as orderState,
                                o.totalPrice as totalPrice,o.totalCount as totalCount,
                                o.receiveAddress as receiveAddress,o.tel as tel,o.receivePerson as receivePerson,
                                g.id as goodsId,g.name as name,g.imageName as imageName,od.price as price,
                                od.count as count,od.evaluate as evaluate
                                from Orders o,OrderDetails od,Goods g where o.id = od.orderId and od.goodsId = g.id 
                                and o.accountId='{0}'";
                str = string.Format(str, id);
                DataTable        dt = ExecuteSql(db.Database.Connection.ConnectionString, str);
                List <DTO.Order> ls = new List <DTO.Order>();

                DTO.Order obj     = null;
                Guid      orderId = default(Guid);
                foreach (DataRow item in dt.Rows)
                {
                    if (orderId != (Guid)item["orderId"])
                    {
                        orderId = (Guid)item["orderId"];
                        obj     = new DTO.Order();
                        ls.Add(obj);
                        obj.id              = (Guid)item["orderId"];
                        obj.orderNo         = (long)item["orderNo"];
                        obj.orderState      = (int)item["orderState"];
                        obj.totalPrice      = (decimal)item["totalPrice"];
                        obj.totalCount      = (int)item["totalCount"];
                        obj.receiveAddress  = item["receiveAddress"].ToString();
                        obj.tel             = item["tel"].ToString();
                        obj.receivePerson   = item["receivePerson"].ToString();
                        obj.orderDetailList = new List <DTO.OrderDetail>();
                    }
                    var subObj = new DTO.OrderDetail();
                    obj.orderDetailList.Add(subObj);
                    subObj.id        = (Guid)item["goodsId"];
                    subObj.name      = item["name"].ToString();
                    subObj.imageName = item["imageName"].ToString();
                    subObj.price     = (decimal)item["price"];
                    subObj.count     = (int)item["count"];
                    subObj.evaluate  = (byte)item["evaluate"];
                }

                list.SetDTOObject(ls);
                //string str = string.Format(@"select * from orders o,goods g,orderdetail od from ")
                //var orderList = db.Orders.Where(p=>p.accountId == id).ToList();
                //list.SetDTOObject(orderList.ToDTOs());
                return(list);
            }
            catch (Exception ex)
            {
                list.SetFailedInformation(ex.Message, null);
                return(list);
            }
        }
Exemplo n.º 11
0
        private static void StaticSetAddressUndefault(ref MissFreshEntities db, Guid userId)
        {
            var addressList = db.Addresses.Where(p => p.accountId == userId).ToList();

            foreach (var item in addressList)
            {
                item.defaultAddress = false;
            }
        }
Exemplo n.º 12
0
        public static ReturnJasonConstruct <IList <DTO.MealsOrder> > GetAllOrder(Guid id)
        {
            ReturnJasonConstruct <IList <DTO.MealsOrder> > list = new ReturnJasonConstruct <IList <DTO.MealsOrder> >();

            try
            {
                MissFreshEntities db  = new MissFreshEntities();
                string            str = @"select mo.id as orderId,mo.orderNo as orderNo,mo.orderState as orderState,
                                mo.totalPrice as totalPrice,mo.totalCount as totalCount,mo.receiveAddress as receiveAddress,
                                mo.tel as tel,mo.receivePerson as receivePerson,m.name as mealsName,g.id as goodsId,g.name as name,
                                g.detailName as detailName,g.evaluate as evaluate,g.imageName as imageName 
                                from MealsOrders mo,MealsOrderDetails mod,Meals m,MealsDetails md,Goods g 
                                where mo.id=mod.mealsOrderId and mod.mealsId=m.id and m.id=md.mealsId 
                                                            and md.goodsId=g.id and accountId = '{0}'";
                str = string.Format(str, id);
                DataTable dt = ExecuteSql(db.Database.Connection.ConnectionString, str);

                Guid                  orderId = default(Guid);
                DTO.MealsOrder        obj     = null;
                List <DTO.MealsOrder> ls      = new List <DTO.MealsOrder>();
                foreach (DataRow dr in dt.Rows)
                {
                    if (orderId != (Guid)dr["orderId"])
                    {
                        orderId = (Guid)dr["orderId"];
                        obj     = new DTO.MealsOrder();
                        ls.Add(obj);
                        obj.id             = (Guid)dr["orderId"];
                        obj.orderNo        = (long)dr["orderNo"];
                        obj.orderState     = (int)dr["orderState"];
                        obj.totalPrice     = (decimal)dr["totalPrice"];
                        obj.totalCount     = (int)dr["totalCount"];
                        obj.mealsName      = dr["mealsName"].ToString();
                        obj.receiveAddress = dr["receiveAddress"].ToString();
                        obj.tel            = dr["tel"].ToString();
                        obj.receivePerson  = dr["receivePerson"].ToString();
                        obj.orderDetail    = new List <DTO.MealsOrderDetail>();
                    }
                    var subObj = new DTO.MealsOrderDetail();
                    obj.orderDetail.Add(subObj);
                    subObj.id         = (Guid)dr["goodsId"];
                    subObj.name       = dr["name"].ToString();
                    subObj.detailName = dr["detailName"].ToString();
                    subObj.evaluate   = (byte)dr["evaluate"];
                    subObj.imageName  = dr["imageName"].ToString();
                }
                list.SetDTOObject(ls);
                return(list);
            }
            catch (Exception ex)
            {
                list.SetFailedInformation(ex.Message, null);
                return(list);
            }
        }
Exemplo n.º 13
0
 public static IEnumerable <DTO.Category> GetAllCategory()
 {
     try
     {
         MissFreshEntities      db   = new MissFreshEntities();
         List <Models.Category> list = db.Categorys.ToList();
         return(list.ToDTOs());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Wether an account exist
 /// </summary>
 /// <param name="telNo">cell phone number</param>
 /// <returns></returns>
 static public bool Exist(string telNo)
 {
     try
     {
         MissFreshEntities db = new MissFreshEntities();
         var count            = db.Customers.Count(p => p.telNo == telNo);
         return(count > 0);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 15
0
        public static ReturnJasonConstruct <DTO.Order> Create(DTO.Order order)
        {
            ReturnJasonConstruct <DTO.Order> DTOObject = new ReturnJasonConstruct <DTO.Order>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var model            = order.ToModel();
                model.createTime = DateTime.Now;
                var temp = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}",
                                         model.createTime.Year, model.createTime.Month,
                                         model.createTime.Day, model.createTime.Hour,
                                         model.createTime.Minute, model.createTime.Second,
                                         model.createTime.Millisecond);

                model.orderNo = long.Parse(temp);
                if (order.orderDetailList.Count == 0)
                {
                    DTOObject.SetWarningInformation("订单信息为空.请选择需要购买的菜品.");
                    return(DTOObject);
                }

                //set the first goodsimage for order image
                Guid goodsId = order.orderDetailList[0].id;
                var  goods   = db.Goods.SingleOrDefault(p => p.id == goodsId);
                model.imangeName = goods.imageName;
                foreach (var item in order.orderDetailList)
                {
                    var goodsInfo = db.Goods.Single(p => p.id == item.id);
                    goodsInfo.stock -= item.count;
                    if (goodsInfo.stock < 0)
                    {
                        DTOObject.SetWarningInformation("很抱歉,所选菜品中库存不足.");
                        return(DTOObject);
                    }
                }
                db.Orders.Add(model);
                db.SaveChanges();
                DTOObject.SetDTOObject(model.ToDTO());
                return(DTOObject);
            }
            catch (Exception ex)
            {
                DTOObject.SetFailedInformation(ex.Message, null);
                return(DTOObject);
            }
        }
Exemplo n.º 16
0
        public static ReturnJasonConstruct <DTO.Goods> GetEntireGoodsInformation(Guid goodsId)
        {
            ReturnJasonConstruct <DTO.Goods> obj = new ReturnJasonConstruct <DTO.Goods>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var goods            = db.Goods.SingleOrDefault(p => p.id == goodsId);
                obj.SetDTOObject(goods.ToDTO());
                return(obj);
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
        }
Exemplo n.º 17
0
        static public ReturnJasonConstruct <IList <DTO.Meals> > GetAllMeals()
        {
            ReturnJasonConstruct <IList <DTO.Meals> > list = new ReturnJasonConstruct <IList <DTO.Meals> >();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var mealsList        = db.Meals.ToList();
                list.SetDTOObject(mealsList.ToDTOs());
                return(list);
            }
            catch (Exception ex)
            {
                list.SetFailedInformation(ex.Message, null);
                return(list);
            }
        }
Exemplo n.º 18
0
        public static ReturnJasonConstruct <IList <DTO.AddressConfig> > GetAllNumber(Guid parentId)
        {
            ReturnJasonConstruct <IList <DTO.AddressConfig> > obj = new ReturnJasonConstruct <IList <DTO.AddressConfig> >();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var list             = db.AddressConfigs.Where(p => p.layer == ((int)layer.number) && p.parentId == parentId).ToList();
                obj.SetDTOObject(list.ToDTOs());
                return(obj);
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
        }
Exemplo n.º 19
0
        public static ReturnJasonConstruct <IList <DTO.Address> > GetAllAddress(Guid accountId)
        {
            ReturnJasonConstruct <IList <DTO.Address> > obj = new ReturnJasonConstruct <IList <DTO.Address> >();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var list             = db.Addresses.Where(p => p.accountId == accountId).ToList();
                obj.SetDTOObject(list.ToDTOs());
                return(obj);
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
        }
Exemplo n.º 20
0
        public static ReturnJasonConstruct <DTO.Address> GetDefaultAddress(Guid accountId)
        {
            ReturnJasonConstruct <DTO.Address> obj = new ReturnJasonConstruct <DTO.Address>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var address          = db.Addresses.SingleOrDefault(p => p.accountId == accountId && p.defaultAddress == true);
                obj.SetDTOObject(address.ToDTO());
                return(obj);
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
        }
Exemplo n.º 21
0
        public static ReturnJasonConstruct <IList <DTO.Goods> > GetAllGoods()
        {
            List <DTO.Goods> aa = new List <DTO.Goods>();
            ReturnJasonConstruct <IList <DTO.Goods> > list = new ReturnJasonConstruct <IList <DTO.Goods> >();

            try
            {
                MissFreshEntities  db        = new MissFreshEntities();
                List <Models.Good> goodsList = db.Goods.ToList();
                list.SetDTOObject(goodsList.ToDTOs());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(list);
        }
Exemplo n.º 22
0
        public static ReturnJasonConstruct <bool> Delete(Guid id)
        {
            ReturnJasonConstruct <bool> obj = new ReturnJasonConstruct <bool>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var addressObj       = db.Addresses.SingleOrDefault(p => p.id == id);
                db.Addresses.Remove(addressObj);
                db.SaveChanges();
                obj.SetDTOObject(true);
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, false);
                return(obj);
            }
            return(obj);
        }
Exemplo n.º 23
0
        public static ReturnJasonConstruct <DTO.AddressConfig> CreateAddressConfig(DTO.AddressConfig dto)
        {
            ReturnJasonConstruct <DTO.AddressConfig> obj = new ReturnJasonConstruct <DTO.AddressConfig>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var model            = dto.ToModel();
                model.id = Guid.NewGuid();
                db.AddressConfigs.Add(model);
                db.SaveChanges();
                obj.SetDTOObject(model.ToDTO());
                return(obj);
            }
            catch (Exception ex)
            {
                obj.SetFailedInformation(ex.Message, null);
                return(obj);
            }
        }
Exemplo n.º 24
0
        public static ReturnJasonConstruct <DTO.Order> GetEntireOrderInformation(Guid id)
        {
            ReturnJasonConstruct <DTO.Order> list = new ReturnJasonConstruct <DTO.Order>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var order            = db.Orders.SingleOrDefault(p => p.id == id);
                list.SetDTOObject(order.ToDTO());
                foreach (var item in list.DTOObject.orderDetailList)
                {
                    item.name = db.Goods.Single(p => p.id == item.id).name;
                }
                return(list);
            }
            catch (Exception ex)
            {
                list.SetFailedInformation(ex.Message, null);
                return(list);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Wether an account
        /// </summary>
        /// <param name="telNo"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        static public ReturnJasonConstruct <Guid> GetAccountId(string telNo, string password)
        {
            ReturnJasonConstruct <Guid> obj = new ReturnJasonConstruct <Guid>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var model            = db.Accounts.SingleOrDefault(p => p.Customer.telNo == telNo && p.Customer.password == password);
                if (model == null)
                {
                    obj.SetWarningInformation("无法找到对应的用户.");
                    return(obj);
                }
                obj.SetDTOObject(model.id);
                return(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 26
0
        public static ReturnJasonConstruct <DTO.Account> Update(DTO.Account account)
        {
            ReturnJasonConstruct <DTO.Account> obj = new ReturnJasonConstruct <DTO.Account>();

            try
            {
                Models.Account    acc = account.ToModel();
                MissFreshEntities db  = new MissFreshEntities();
                var model             = db.Accounts.SingleOrDefault(p => p.Customer.telNo == acc.Customer.telNo && p.Customer.password == null);
                if (model == null)
                {
                    obj.SetWarningInformation("用于已存在!请检查手机号输入是否正确.");
                    return(obj);
                }
                else
                {
                    if (model.code == acc.code)
                    {
                        model.code = SMS.GetRandomCode().ToString();
                        model.Customer.firstName = acc.Customer.firstName;
                        model.Customer.lastName  = acc.Customer.lastName;
                        model.Customer.email     = acc.Customer.email;
                        model.Customer.password  = acc.Customer.password;
                        db.SaveChanges();
                        obj.SetDTOObject(model.ToDTO());
                    }
                    else
                    {
                        obj.SetWarningInformation("验证码输入错误,请重新输入.");
                    }
                    return(obj);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 27
0
        public static ReturnJasonConstruct <DTO.Order> CloseOrder(Guid id)
        {
            ReturnJasonConstruct <DTO.Order> DTOObject = new ReturnJasonConstruct <DTO.Order>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var order            = db.Orders.SingleOrDefault(p => p.id == id);
                if (order.orderState != (int)orderStatus.Created)
                {
                    DTOObject.SetWarningInformation("只有创建后未支付的订单可以关闭.");
                    return(DTOObject);
                }
                order.orderState = (int)orderStatus.close;
                db.SaveChanges();
                DTOObject.SetDTOObject(order.ToDTO());
                return(DTOObject);
            }
            catch (Exception ex)
            {
                DTOObject.SetFailedInformation(ex.Message, null);
                return(DTOObject);
            }
        }