public bool Create(ResponsibleClassViewModel responsibleClassViewModel) { bool ret = false; try { ResponsibleClass r = new ResponsibleClass(); r.Name = responsibleClassViewModel.Name; r.UserID = responsibleClassViewModel.UserID; r.UserID2 = responsibleClassViewModel.UserID2; r.SubAreaID = "tp01"; db.ResponsibleClass.Add(r); db.SaveChanges(); ret = true; } catch { } return ret; }
public IQueryable<ResponsibleClassViewModel> Read() { List<ResponsibleClassViewModel> ret = new List<ResponsibleClassViewModel>(); var qry = db.ResponsibleClass; foreach (ResponsibleClass o in qry) { ResponsibleClassViewModel r = new ResponsibleClassViewModel(); r.ID = o.ID; r.Name = o.Name; r.SubAreaID = o.SubAreaID; r.UserID = o.UserID; r.UserID2 = o.UserID2; r.UserName = o.UserData2.UserName; if (r.UserID2 != null) r.UserName2 = o.UserData1.UserName; else r.UserName2 = ""; ret.Add(r); } return ret.AsQueryable(); }
public bool Delete(ResponsibleClassViewModel responsibleClassViewModel) { bool ret = false; try { ResponsibleClass r = db.ResponsibleClass.Find(responsibleClassViewModel.ID); db.ResponsibleClass.Remove(r); db.SaveChanges(); ret = true; } catch { } return ret; }
public bool Update(ResponsibleClassViewModel responsibleClassViewModel) { bool ret = false; try { ResponsibleClass r = db.ResponsibleClass.Find(responsibleClassViewModel.ID); r.Name = responsibleClassViewModel.Name; r.UserID = responsibleClassViewModel.UserID; r.UserID2 = responsibleClassViewModel.UserID2; //r.SubAreaID = "tp01"; db.SaveChanges(); ret = true; } catch (DbUpdateConcurrencyException ex) { // Update the values of the entity that failed to save from the store ex.Entries.Single().Reload(); } catch (DbEntityValidationException ex) { 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); } return ret; }