public ActionResult DeleteCity(CityViewModel item) { try { City c = db.Cities.Find(item.ToModel().Id); if (c != null) { c.IsDeleted = true; c.DeletionDate = DateTime.Now; db.SaveChanges(); } return(new HttpStatusCodeResult(200)); } catch { LogViewModel l = new LogViewModel { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, Type = "Deletion", Message = "failed to delete city " + this.Name + " to database" }; l.AddLog(l); return(new HttpStatusCodeResult(400)); } }
private int GetSurveyTotal(Guid id) { int tot = 0; var user = db.Cities.Where(x => x.CountryId == Id).Select(x => x); CityViewModel c = new CityViewModel(); foreach (var item in user) { if (item.IsDeleted == false) { tot += c.GetSurveyTotal(item.Id); } } return(tot); }
public ActionResult UpdateCity(CityViewModel item) { try { City c = db.Cities.Find(item.ToModel().Id); if (c != null) { c.Id = item.Id; c.CountryId = item.CountryId; c.Name = item.Name; c.ModifiedDate = DateTime.Now; c.ModifiedUserId = item.ModifiedUserId; c.IsDeleted = item.IsDeleted; c.DeletionDate = item.DeletionDate; c.DeletionUserId = item.DeletionUserId; c.Users = item.GetUserList(item.Users); c.Country = db.Countries.Find(c.CountryId); //c.CreatedDate = item.CreatedDate; c.CreatedUserId = item.CreatedUserId; db.SaveChanges(); } return(new HttpStatusCodeResult(200)); } catch { LogViewModel l = new LogViewModel { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, Type = "Update", Message = "failed to update city " + this.Name + " to database" }; l.AddLog(l); return(new HttpStatusCodeResult(400)); } }
public ActionResult AddCity(CityViewModel item) { try { City c = item.ToModel(); c.Users = item.GetUserList(item.Users); c.CreatedDate = DateTime.Now; db.Cities.Add(c); db.SaveChanges(); return(new HttpStatusCodeResult(200)); } catch { LogViewModel l = new LogViewModel { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, Type = "Insertion", Message = "failed to insert city " + this.Name + " to database" }; l.AddLog(l); return(new HttpStatusCodeResult(400)); } }