public int Check_Code_Front(SalesCodeModelShow item) { try { s26webDataContext db = new s26webDataContext(); //取得促銷碼資料 var Sale = db.SalesCode.FirstOrDefault(w => w.Code == item.Code); //取得會員資料 var Vol = db.Volunteers.FirstOrDefault(f => f.Id == item.VolunteersId); if (Sale != null && Vol != null) { if (Sale.ExchangeStatus == true) { return -1; } if (Vol.Point == null) { Vol.Point = 0; } Vol.Point += Sale.SalesPromotionPoint; Sale.ExchangeStatus = true; Sale.ExchangeTime = DateTime.UtcNow.AddHours(-8); Sale.VolunteersId = item.VolunteersId; Sale.VolunteersCreateTime = Vol.CreateTime; db.SubmitChanges(); db.Connection.Close(); return Sale.Id; } db.Connection.Close(); return -2; } catch { return -2; } }
public int Update(SalesCodeModelShow item) { try { s26webDataContext db = new s26webDataContext(); var data = db.SalesCode.FirstOrDefault(f => f.Id == item.Id); if (data != null) { data.Code = item.Code; data.SalesPromotionId = item.SalesPromotionId; data.SalesPromotionPoint = item.SalesPromotionPoint; data.SalesPromotionDeadline = item.SalesPromotionDeadline; db.SubmitChanges(); db.Connection.Close(); return data.Id; } db.Connection.Close(); return -1; } catch { return -1; } }
public SalesCodeModelShow Get_One(int id) { s26webDataContext db = new s26webDataContext(); SalesCodeModelShow data = new SalesCodeModelShow(); var item = db.SalesCode.FirstOrDefault(f => f.Id == id); data.Code = item.Code; data.SalesPromotionId = item.SalesPromotionId; data.SalesPromotionPoint = item.SalesPromotionPoint; data.SalesPromotionDeadline = item.SalesPromotionDeadline.AddHours(8); data.CreateTime = item.CreateTime.AddHours(8); db.Connection.Close(); return data; }
public int Insert(SalesCodeModelShow item) { s26webDataContext db = new s26webDataContext(); try { SalesCode new_item = new SalesCode { Code = item.Code, SalesPromotionId = item.SalesPromotionId, SalesPromotionPoint = Get_SalesPromotionPoint(item.SalesPromotionId), SalesPromotionDeadline = Get_SalesPromotionDeadline(item.SalesPromotionId), ExchangeStatus = false, VolunteersId = 0, CreateTime = DateTime.UtcNow }; db.SalesCode.InsertOnSubmit(new_item); db.SubmitChanges(); db.Connection.Close(); return new_item.Id; } catch { return -1; } }
public List<SalesCodeModelShow> Convert(List<SalesCode> item) { List<SalesCodeModelShow> result = new List<SalesCodeModelShow>(); foreach (var i in item) { if (i.ExchangeTime != null && i.VolunteersCreateTime != null) { var Sales = new SalesCodeModelShow { Id = i.Id, Code = i.Code, SalesPromotionId = i.SalesPromotionId, SalesPromotionName = Get_SalesPromotionName(i.SalesPromotionId), SalesPromotionDeadline = i.SalesPromotionDeadline, SalesPromotionPoint = i.SalesPromotionPoint, ExchangeStatus = i.ExchangeStatus, ExchangeTime = i.ExchangeTime.Value.AddHours(8), VolunteersId = i.VolunteersId, VolunteersCreateTime = i.VolunteersCreateTime.Value.AddHours(8), CreateTime = i.CreateTime.AddHours(8), }; result.Add(Sales); } else { var Sales = new SalesCodeModelShow { Id = i.Id, Code = i.Code, SalesPromotionId = i.SalesPromotionId, SalesPromotionName = Get_SalesPromotionName(i.SalesPromotionId), SalesPromotionDeadline = i.SalesPromotionDeadline, SalesPromotionPoint = i.SalesPromotionPoint, ExchangeStatus = i.ExchangeStatus, VolunteersId = i.VolunteersId, CreateTime = i.CreateTime.AddHours(8), }; result.Add(Sales); } } return result; }