public static Order insertOrder(Order o) { dataContext = new RobaSegonaMaEntities(); try { dataContext.Orders.Add(o); dataContext.SaveChanges(); Cloth c = dataContext.Clothes.Where(x => x.Id == o.Clothes_Id && x.active == true).FirstOrDefault(); c.active = false; Requestor r = dataContext.Requestors.FirstOrDefault(x => x.Id == o.Requestor_Id); r.points += c.Classification.value; dataContext.SaveChanges(); return(o); } catch (Exception e) { return(null); } dataContext = new RobaSegonaMaEntities(); }
public static RewardInfoLang UpdateRewardInfoLang(int id, RewardInfoLang val) { try { RewardInfoLang c0 = dataContext.RewardInfoLangs.Where(x => x.Id == id).SingleOrDefault(); if (val.Id != null) { c0.Id = val.Id; } if (val.title != null) { c0.title = val.title; } if (val.description != null) { c0.description = val.description; } dataContext.SaveChanges(); return(GetRewardInfoLang(id)); } catch (Exception e) { return(null); } }
public static Reward UpdateReward(int id, Reward val) { try { Reward c0 = dataContext.Rewards.Where(x => x.Id == id).SingleOrDefault(); if (val.Id != null) { c0.Id = val.Id; } if (val.active != null) { c0.active = val.active; } if (val.neededPoints != null) { c0.neededPoints = val.neededPoints; } if (val.RewardInfoLangs.Any()) { val.RewardInfoLangs = UpdateInfoRewardFromList(val.RewardInfoLangs.ToList()); } dataContext.SaveChanges(); return(GetReward(id)); } catch (Exception e) { return(null); } }
public static Status InsertStatus(Status c) { try { dataContext.Status.Add(c); dataContext.SaveChanges(); return(GetStatus(c.Id)); } catch (Exception e) { return(null); } }
public static Announcement insertAnnouncement(Announcement c) { try { dc.Announcements.Add(c); dc.SaveChanges(); return(c); } catch (Exception e) { return(null); } }
public static Requestor InsertRequestor(Requestor c) { try { dataContext.Requestors.Add(c); dataContext.SaveChanges(); return(GetRequestor(c.Id)); } catch (Exception e) { return(null); } }
public static Administrator InsertAdministrator(Administrator c) { try { c.Language = null; dataContext.Administrators.Add(c); dataContext.SaveChanges(); return(GetAdministrator(c.Id)); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
public static bool claimRewardByDonor(int rewardId, int donorId) { dataContext = new RobaSegonaMaEntities(); Reward r = dataContext.Rewards.Where(x => x.Id == rewardId).FirstOrDefault(); Donor d = dataContext.Donors.Where(x => x.Id == donorId).FirstOrDefault(); if (r.neededPoints > d.points) { return(false); } try { if (r.Donors == null) { r.Donors = new List <Donor>(); } r.Donors.Add(d); d.Rewards.Add(r); d.points -= r.neededPoints; dataContext.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public static Cloth insertCloth(Cloth c) { try { dc.Clothes.Add(c); dc.SaveChanges(); dc = new RobaSegonaMaEntities(); return(c); } catch (Exception e) { return(null); } }
public static Reward UpdateReward(int id, Reward val) { try { Reward c0 = dataContext.Rewards.Where(x => x.Id == id).FirstOrDefault(); val.dateCreated = c0.dateCreated; DeleteReward(c0.Id); InsertReward(val); dataContext.SaveChanges(); return(GetReward(id)); } catch (Exception e) { return(null); } }
public static Donor InsertDonor(Donor c) { try { if (c.ammountGiven == null) { c.ammountGiven = 0; } if (c.points == null) { c.points = 0; } dataContext.Donors.Add(c); dataContext.SaveChanges(); dataContext = new RobaSegonaMaEntities(false); return(GetDonor(c.Id)); } catch (Exception e) { return(null); } }
public static Requestor UpdateRequestorPassword(int id, Requestor c) { try { dataContext = new RobaSegonaMaEntities(); Requestor c0 = dataContext.Requestors.Where(x => x.Id == id).SingleOrDefault(); if (c.password != null) { c0.password = c.password; } dataContext.SaveChanges(); return(GetRequestor(id)); } catch (Exception e) { return(null); } }
public static Warehouse addWarehouse(Warehouse w) { dc.Warehouses.Add(w); dc.SaveChanges(); return(w); }
public static Requestor UpdateRequestor(int id, Requestor c) { try { dataContext = new RobaSegonaMaEntities(); Requestor c0 = dataContext.Requestors.Where(x => x.Id == id).SingleOrDefault(); if (c.name != null) { c0.name = c.name; } if (c.lastName != null) { c0.lastName = c.lastName; } if (c.birthDate != null) { c0.birthDate = c.birthDate; } if (c.gender != null) { c0.gender = c.gender; } if (c.password != null) { c0.password = c.password; } if (c.email != null) { c0.email = c.email; } if (c.securityAnswer != null) { c0.securityAnswer = c.securityAnswer; } if (c.securityQuestion != null) { c0.securityQuestion = c.securityQuestion; } if (c.dateCreated != null) { c0.dateCreated = c.dateCreated; } if (c.active != null) { c0.active = c.active; } if (c.picturePath != null) { c0.picturePath = c.picturePath; } if (c.Language_Id != null) { c0.Language_Id = c.Language_Id; } if (c.dni != null) { c0.dni = c.dni; } if (c.Status_Id != null) { c0.Status_Id = c.Status_Id; } dataContext.SaveChanges(); return(GetRequestor(id)); } catch (Exception e) { return(null); } }