private SituationViewModel SearchSituation(SituationViewModel situationObject) { var situationDescriptionIsValid = _validate.OnlyLetters(situationObject.Description) == true; var newSituationObject = new SituationViewModel(); if (situationDescriptionIsValid == true) { var situationSearchResult = _situationContext.Collection().Where(s => s.Description.Equals(situationObject.Description, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (situationSearchResult != null) { newSituationObject.Id = situationSearchResult.Id; newSituationObject.Description = situationSearchResult.Description; newSituationObject.Status = situationSearchResult.Status; newSituationObject.ExistInDB = true; } else { newSituationObject.ExistInDB = false; } } newSituationObject.IsValid = situationDescriptionIsValid; return(newSituationObject); }
public static void UpdateSituation(this Situation situation, SituationViewModel situationVm) { situation.ID = situationVm.ID; situation.Name = situationVm.Name; situation.Alias = situationVm.Alias; situation.SituationCategoryID = situationVm.SituationCategoryID; situation.Image = situationVm.Image; situation.MoreImages = situationVm.MoreImages; situation.Description = situationVm.Description; situation.Content = situationVm.Content; situation.HomeFlag = situationVm.HomeFlag; situation.HotFlag = situationVm.HotFlag; situation.ViewCount = situationVm.ViewCount; situation.Tags = situationVm.Tags; situation.Place = situationVm.Place; situation.TheInjured = situationVm.TheInjured; situation.TheDead = situationVm.TheDead; situation.PropertyDamage = situationVm.PropertyDamage; situation.SettleBodyID = situationVm.SettleBodyID; situation.ResolvedSituationID = situationVm.ResolvedSituationID; situation.CreatedDate = situationVm.CreatedDate; situation.CreatedBy = situationVm.CreatedBy; situation.UpdatedBy = situationVm.UpdatedBy; situation.UpdatedDate = situationVm.UpdatedDate; situation.MetaKeyword = situationVm.MetaKeyword; situation.MetaDescription = situationVm.MetaDescription; situation.Status = situationVm.Status; }
private void PostNewSituationToDB(SituationViewModel situationObject) { var situationToInsert = new Situation(); situationToInsert.Description = situationObject.Description; situationToInsert.Status = situationObject.Status; _situationContext.Insert(situationToInsert); _situationContext.Commit(); _logger.Info("Inserted record Id " + situationToInsert.Id + " into Table " + tableNameUsedByLogger); }
public JsonResult SearchSituationDescription(SituationViewModel situationObject) { try { var searchSituationResult = _situationService.EvaluateSituationDescriptionBeforeSearching(situationObject); return(Json(searchSituationResult, JsonRequestBehavior.AllowGet)); } catch (Exception) { throw; } }
public SituationViewModel EvaluateSituationDescriptionBeforeSearching(SituationViewModel situationToEvaluate) { if (string.IsNullOrEmpty(situationToEvaluate.Description) == false) { return(SearchSituation(situationToEvaluate)); } else { return(new SituationViewModel(situationToEvaluate.Id, situationToEvaluate.Description, situationToEvaluate.Status, false, false)); } }
private void UpdateSituationData(SituationViewModel situationObject) { var situationToUpdate = _situationContext.Find(situationObject.Id); if (situationToUpdate != null) { _logger.Info("Found record Id " + situationToUpdate.Id + " in Table " + tableNameUsedByLogger); situationToUpdate.Description = situationObject.Description; situationToUpdate.Status = situationObject.Status; _situationContext.Commit(); _logger.Info("Updated record Id " + situationToUpdate.Id + " in Table " + tableNameUsedByLogger); } }
public ActionResult CreateSituation(SituationViewModel model) { var username = HttpContext.GetOwinContext().Authentication.User.Identity.Name; var user = db.Users.SingleOrDefault(u => u.Username == username); db.Situations.Add(new Situation { Name = model.Name, Description = model.Description, UserId = model.UserId, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }); db.SaveChanges(); return(RedirectToAction("MySituations")); }
public SituationViewModel EvaluateSituationDescriptionBeforeAdding(SituationViewModel situationObject) { if (string.IsNullOrEmpty(situationObject.Description) == false) { //Validate that situation description field contains only letters bool descriptionHasOnlyLetters = _validate.OnlyLetters(situationObject.Description); if (descriptionHasOnlyLetters == true) { bool situationExistInDatabase = SituationAlreadyExistInDatabase(situationObject.Description); //Validate that description is not in database already if (situationExistInDatabase == false) { PostNewSituationToDB(situationObject); } return(new SituationViewModel(situationObject.Id, situationObject.Description, situationObject.Status, situationExistInDatabase, descriptionHasOnlyLetters)); } } //At this point Situation Description does not contains only letters thus return IsValid as false return(new SituationViewModel(situationObject.Id, situationObject.Description, situationObject.Status, false, false)); }
public SituationViewModel EvaluateSituationDescriptionBeforeUpdating(SituationViewModel situationObject) { bool situationExistInDB; bool situationIsValid; if (string.IsNullOrEmpty(situationObject.Description) == false) { situationIsValid = _validate.OnlyLetters(situationObject.Description); if (situationIsValid == true) { situationExistInDB = SituationAlreadyExistInDatabase(situationObject.Description); if (situationExistInDB == false) { UpdateSituationData(situationObject); } return(new SituationViewModel(situationObject.Id, situationObject.Description, situationObject.Status, situationExistInDB, situationIsValid)); } } //At this point Situation Description is null or empty so return IsValid as false return(new SituationViewModel(situationObject.Id, situationObject.Description, situationObject.Status, false, false)); }
public ActionResult MySituations() { var username = HttpContext.GetOwinContext().Authentication.User.Identity.Name; var user = db.Users.SingleOrDefault(u => u.Username == username); var situations = db.Situations.Where(s => s.UserId == user.Id); var model = new List <SituationViewModel>(); foreach (var item in situations) { var modelItem = new SituationViewModel { Id = item.Id, Name = item.Name, Description = item.Description, CreatedOn = item.CreatedOn, UpdatedOn = item.UpdatedOn, User = item.User }; int score = db.Votes.Where(v => v.Value > 0 && v.EntityGroup == "Situation" && v.EntityId == item.Id).Count() - db.Votes.Where(v => v.Value < 0 && v.EntityGroup == "Situation" && v.EntityId == item.Id).Count(); modelItem.Score = score; model.Add(modelItem); } return(View(model)); }
public ActionResult CreateSituation() { var model = new SituationViewModel(); return(View(model)); }