Example #1
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);
            }
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }
Example #4
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);
        }
Example #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);
            }
        }
Example #6
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);
        }
Example #7
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);
            }
        }
Example #8
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);
            }
        }
Example #9
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);
            }
        }
Example #10
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);
            }
        }
Example #11
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);
            }
        }
Example #12
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);
            }
        }
Example #13
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);
            }
        }
Example #14
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);
            }
        }
Example #15
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);
        }
Example #16
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);
            }
        }
Example #17
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);
            }
        }
Example #18
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);
            }
        }