public void Edit(Item item) { using (lostfoundDB db = new lostfoundDB()) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } }
public void DeleteItem(int?id) { using (lostfoundDB db = new lostfoundDB()) { ITEM item = db.ITEMs.Find((int)id); db.ITEMs.Remove(item); db.SaveChanges(); } }
public void AddType(ItemType data) { using (lostfoundDB db = new lostfoundDB()) { ITEMTYPE type = new ITEMTYPE { TITLE = data.Title }; db.ITEMTYPEs.Add(type); db.SaveChanges(); } }
public void AddCategory(Category data) { using (lostfoundDB db = new lostfoundDB()) { CATEGORY category = new CATEGORY { TITLE = data.Title }; db.CATEGORies.Add(category); db.SaveChanges(); } }
public void AddColor(Color data) { using (lostfoundDB db = new lostfoundDB()) { COLOR color = new COLOR { TITLE = data.Title }; db.COLORs.Add(color); db.SaveChanges(); } }
/*############################################### Items Manager ###############################################*/ public void CreateItem(Item data) { using (lostfoundDB db = new lostfoundDB()) { REPORTER reporter = new REPORTER { FIRSTNAME = data.FirstName, LASTNAME = data.LastName, EMAIL = data.Email, PHONENUMBER = data.PhoneNumber, IDDOCUMENT = data.VerificationDocument, AUB = data.AUB }; db.REPORTERs.Add(reporter); ITEM item = new ITEM { ITEMID = UniqueID("Item"), REPORTERID = reporter.REPORTERID, ITEMTYPEID = data.ItemTypeID, CREATEDDATE = DateTime.Now.Date, STATEID = data.StateID, FLDATE = DateTime.Now.Date, CATEGORYID = data.CategoryID, COLORID = data.ColorID, LOCATIONID = data.LocationID, IMAGE = data.Image, NOTES = data.Notes }; db.ITEMs.Add(item); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } }
public void AddRole(Role data) { using (lostfoundDB db = new lostfoundDB()) { ROLE role = new ROLE { TITLE = data.Title }; db.ROLEs.Add(role); db.SaveChanges(); } }
public void AddState(State data) { using (lostfoundDB db = new lostfoundDB()) { STATE state = new STATE { TITLE = data.Title }; db.STATEs.Add(state); db.SaveChanges(); } }
public void AddLocation(Location data) { using (lostfoundDB db = new lostfoundDB()) { LOCATION location = new LOCATION { TITLE = data.Title }; db.LOCATIONs.Add(location); db.SaveChanges(); } }
/*############################################### Preferences Manager ###############################################*/ public void CreateAccount(User user) { using (lostfoundDB db = new lostfoundDB()) { USER staff = new USER { USERID = UniqueID("User"), FIRSTNAME = user.FirstName, LASTNAME = user.LastName, EMAIL = user.Email, PHONENUMBER = user.PhoneNumber, PASSWORD = Encrypt(user.Password), }; staff.ROLEID = user.RoleID; db.USERs.Add(staff); db.SaveChanges(); } }