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); } }
/// <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; } }
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); }
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); } }
private bool CheckObjectAvalible(DTO.User user, ref ReturnJasonConstruct <DTO.User> dto) { if (user.name.Length > 20) { dto.status = (int)executeStatus.warning; dto.information = "用户名称不能大于20个中英文字符."; return(false); } if (user.tel.Length != 11) { dto.status = (int)executeStatus.warning; dto.information = "手机号码必须为11位."; return(false); } if (user.password == null) { dto.status = (int)executeStatus.warning; dto.information = "用户密码不能为空."; return(false); } if (user.password.Length < 6 || user.password.Length > 20) { dto.status = (int)executeStatus.warning; dto.information = "用户密码必须大于6位小于20位."; return(false); } return(true); }
public ReturnJasonConstruct <DTO.User> SetUserShare([FromBody] DTO.User user) { DateTime dt = DateTime.Now; DateTime startTime = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0); dt = dt.AddDays(1); DateTime endTime = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0); UserInformationEntities db = new UserInformationEntities(); var lotteryObjects = db.lottery1.Where(p => p.UserID == user.id && p.LotteryDate >= startTime && p.LotteryDate <= endTime).ToList(); ReturnJasonConstruct <DTO.User> dto = new ReturnJasonConstruct <DTO.User>(); //检查当天有没有抽过奖。如果抽过奖,直接跳过。 if (lotteryObjects.Count == 0) { dto.status = (int)executeStatus.warning; dto.information = "今天还没有抽奖"; } else if (lotteryObjects.Count == 1 && !lotteryObjects[0].Share) { lotteryObjects[0].Share = true; db.SaveChanges(); dto.status = (int)executeStatus.success; dto.information = "恭喜您获得额外抽奖一次的机会"; } else { dto.status = (int)executeStatus.warning; dto.information = "今天分享获得额外抽奖的次数已经满额,请明天再继续分享."; } return(dto); }
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); }
/// <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; } }
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); } }
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); } }
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); } }
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); } }
public ReturnJasonConstruct <DTO.User> Put([FromBody] DTO.User user) { try { ReturnJasonConstruct <DTO.User> dto = new ReturnJasonConstruct <DTO.User>(); if (CheckObjectAvalible(user, ref dto) == false) { return(dto); } UserInformationEntities db = new UserInformationEntities(); if (user.id.ToString() == "" || db.User.Where(p => p.ID == user.id).Count() == 0) {//创建用户 var result = db.User.Where(p => p.Tel == user.tel); if (result.Count() > 0) { dto.status = (int)executeStatus.warning; dto.information = "该电话号码已经被注册."; return(dto); } Models.User ac = new Models.User(); ac.ID = Guid.NewGuid(); ac.UserName = user.name; ac.Tel = user.tel; ac.Exp = 0; ac.Level = 0; ac.password = user.password; ac.CreateDate = DateTime.Now; db.User.Add(ac); dto.DTOObject = ac.ToDTO(); } else//更新用户 { var result = db.User.Single(p => p.ID == user.id); result.UserName = user.name; result.Tel = user.tel; result.password = user.password; result.Exp = user.exp; result.Level = ConvertDTO.GetLevelInt(user.level); dto.DTOObject = result.ToDTO(); } db.SaveChanges(); dto.status = (int)executeStatus.success; return(dto); } catch (Exception ex) { throw ex; } }
public ReturnJasonConstruct <DTO.Account> Get(string telNo) { DTO.Account ac = new DTO.Account(); ReturnJasonConstruct <DTO.Account> obj = new ReturnJasonConstruct <DTO.Account>(); switch (Services.Account.CanSendCheckCode(telNo)) { case 0: { bool result; int code = SMS.SendMessage(telNo, out result); if (result == false) { obj.status = (int)executeStatus.warning; obj.information = "请勿频繁发送短信,请稍后再次尝试."; return(obj); } Console.WriteLine("******Code is:" + code.ToString()); if (!Services.Account.Exist(telNo)) { return(Services.Account.Create(telNo, code)); } else { return(Services.Account.Update(telNo, code)); } } case 1: { //account exist cannot send check code,please change to another telephone number. obj.status = (int)executeStatus.warning; obj.information = "账户已经存在,请确认手机号填写是否正确."; return(obj); } case 2: { obj.status = (int)executeStatus.warning; obj.information = "验证码每一分钟只能发送一次,请稍后再试."; return(obj); } default: { obj.status = (int)executeStatus.warning; obj.information = "获取验证码出现未知错误,请联系客服."; return(obj); } } }
public ReturnJasonConstruct <DTO.Account> Put([FromBody] DTO.Account dto) { ReturnJasonConstruct <DTO.Account> obj = new ReturnJasonConstruct <DTO.Account>(); if (!Services.Account.Exist(dto.customer.telNo)) { obj.SetWarningInformation("新建用户失败."); return(obj); } else { return(Services.Account.Update(dto)); } }
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); } }
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); } }
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); } }
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); } }
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); }
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); } }
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); } }
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); }
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); } }
/// <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; } }
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); } }
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; } }
public ReturnJasonConstruct <DTO.User> Get(Guid id) { try { ReturnJasonConstruct <DTO.User> dto = new ReturnJasonConstruct <DTO.User>(); UserInformationEntities db = new UserInformationEntities(); if (db.User.Where(p => p.ID == id).Count() == 0) { dto.status = (int)executeStatus.warning; dto.information = "没有该用户或用户名密码不对,请检查键入的用户信息."; return(dto); } var result = db.User.Single(p => p.ID == id); dto.status = (int)executeStatus.success; dto.DTOObject = result.ToDTO(); return(dto); } catch (Exception ex) { throw ex; } }
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); } }
public ReturnJasonConstruct <DTO.RollLettory> Get(Guid userId) { try { DateTime dt = DateTime.Now; ReturnJasonConstruct <DTO.RollLettory> dto = new ReturnJasonConstruct <DTO.RollLettory>(); DateTime startTime = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0); dt = dt.AddDays(1); DateTime endTime = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0); UserInformationEntities db = new UserInformationEntities(); //获取默认奖项 LotteryGift defaultGift = null; if (db.LotteryGift.Where(p => p.GiftName == defaultGiftName).Count() == 0) { dto.status = (int)executeStatus.warning; dto.information = "无法获取默认奖项"; return(dto); } defaultGift = db.LotteryGift.Single(p => p.GiftName == defaultGiftName); //检查抽奖概率基数 LotteryGift selectGift = null; var items = db.LotteryGift.AsQueryable().Where(p => !p.Expired).OrderBy(p => p.ID).ToList(); if (items.Count() == 0) { dto.status = (int)executeStatus.warning; dto.information = "没有抽奖项目."; return(dto); } if (items.Count() != lotteryCount) { dto.status = (int)executeStatus.warning; dto.information = "抽奖项目必须为8个."; return(dto); } //初始化奖品信息 RollLottery rl = new RollLottery(); foreach (var item in items) { rl.SetGift(item.GiftName, item.Probability); } //首先检查是否有指定的礼物,如果有,直接返回。 var gift = db.LotteryGift.Where(p => p.Owner == userId && p.Num > 0).ToList(); if (gift.Count() > 0) { selectGift = gift[0]; dto.status = (int)executeStatus.success; dto.DTOObject = SaveLottery(userId, ref db, ref selectGift, ref defaultGift, ref rl); return(dto); } //var lotteryObjects = db.lottery1.Where(p => p.UserID == userId && p.LotteryDate >= startTime && p.LotteryDate <= endTime).ToList(); ////检查当天有没有抽过奖。如果抽过奖,直接跳过。 //if (!(lotteryObjects.Count == 0 || (lotteryObjects.Count == 1 && lotteryObjects[0].Share))) //{ // dto.status = (int)executeStatus.warning; // dto.information = "今天已经抽过奖了."; // return dto; //} rl.GetProbability(); long index = rl.GetGiftIndex(ref WebApiApplication.randomSeed); var giftObject = items[(int)index]; selectGift = giftObject; dto.status = (int)executeStatus.success; dto.DTOObject = SaveLottery(userId, ref db, ref selectGift, ref defaultGift, ref rl); return(dto); } catch (Exception ex) { throw ex; } }