public void DeleteRestaraunt(int restarauntID) { Restaraunt dbEntry = context.Restaraunts.Find(restarauntID); RestarauntLang dbEntryRestarauntLangs = context.RestarauntLangs.Find(restarauntID); Image dbEntryImages = context.Images.Find(restarauntID); Comment dbEntryComments = context.Comments.Find(restarauntID); if (dbEntry != null) { context.Restaraunts.Remove(dbEntry); } if (dbEntryRestarauntLangs != null) { context.RestarauntLangs.Remove(dbEntryRestarauntLangs); } if (dbEntryImages != null) { context.Images.Remove(dbEntryImages); } if (dbEntryComments != null) { context.Comments.Remove(dbEntryComments); } context.SaveChanges(); }
public RestarauntLang DeleteRestarauntLang(int restarauntLangID) { RestarauntLang dbEntry = context.RestarauntLangs.Find(restarauntLangID); if (dbEntry != null) { context.RestarauntLangs.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public ActionResult GetRestarauntInfo(int restarauntID) { try { if (!restarauntID.Equals(null)) { Restaraunt Restaraunt = restRepository.GetRestarauntByID(restarauntID); RestarauntLang RestarauntLang = restLangRepository.GetRestarauntLangByID(restarauntID); RestarauntAllData result = workWithDBProvider.CreateRestarauntAllData(Restaraunt, RestarauntLang); return(Json(new { result = result })); } return(Json(new { result = "JSON is null" })); } catch { return(Json(new { result = "NaN" })); } }
public ActionResult EditRestaurant(RestaurantData data) { if (!data.Equals(null)) { try { Restaraunt EditRestaraunt = data.RestarauntData; RestarauntLang EditRestLang = data.RestaurantLangData; restRepository.SaveRestaraunt(EditRestaraunt); restLangRepository.SaveRestarauntLang(EditRestLang); return(Json(new { result = "success" })); } catch { return(Json(new { result = "error", message = "Ooooooops! Some troubles was happened with DB." })); } } return(Json(new { result = "error", message = "JSON IS NULL" })); }
public RestarauntAllData CreateRestarauntAllData(Restaraunt restaraunt, RestarauntLang restLang) { RestarauntAllData result = new RestarauntAllData(); result.Address = restLang.Address; result.Country = restLang.Country; result.Locality = restLang.Locality; result.Region = restLang.Region; result.Review = restLang.Review; result.Name = restLang.Name; result.Longitude = restaraunt.Longitude; result.Latitude = restaraunt.Latitude; result.KitchenRate = restaraunt.KitchenRate; result.InteriorRate = restaraunt.InteriorRate; result.MaintenanceRate = restaraunt.MaintenanceRate; result.RestarauntType = restaraunt.RestarauntType; result.AddedDate = restaraunt.AddedDate; result.Images = imageRepository.GetRestarauntImages(restaraunt.RestarauntID); return(result); }
public void SaveRestarauntLang(RestarauntLang restarauntLang) { if (restarauntLang.RestarauntLangID == 0) { context.RestarauntLangs.Add(restarauntLang); } else { RestarauntLang dbEntry = context.RestarauntLangs.Find(restarauntLang.RestarauntLangID); if (dbEntry != null) { dbEntry.Name = restarauntLang.Name; dbEntry.Region = restarauntLang.Region; dbEntry.Locality = restarauntLang.Locality; dbEntry.Country = restarauntLang.Country; dbEntry.Address = restarauntLang.Address; dbEntry.Review = restarauntLang.Review; dbEntry.RestarauntID = restarauntLang.RestarauntID; dbEntry.LanguageID = restarauntLang.LanguageID; } } context.SaveChanges(); }
public ActionResult AddRestaurant(RestaurantData data) { if (!data.Equals(null)) { try { Restaraunt NewRestaraunt = data.RestarauntData; RestarauntLang NewRestLang = data.RestaurantLangData; NewRestaraunt.AddedDate = DateTime.Now; NewRestaraunt.RestarauntType = Restaraunt.RestType.Bar; restRepository.SaveRestaraunt(NewRestaraunt); NewRestLang.LanguageID = 1; NewRestLang.RestarauntID = NewRestaraunt.RestarauntID; restLangRepository.SaveRestarauntLang(NewRestLang); return(Json(new { result = "success", id = NewRestaraunt.RestarauntID })); } catch { return(Json(new { result = "error", message = "Ooooooops! Some troubles was happened with DB." })); } } return(Json(new { result = "error", message = "JSON IS NULL" })); }
public ActionResult GetRestaurantInfo(int restarauntID) { try { if (!restarauntID.Equals(null)) { Restaraunt Restaraunt = restRepository.GetRestarauntByID(restarauntID); RestarauntLang RestarauntLang = restLangRepository.GetRestarauntLangByID(restarauntID); RestarauntAllData result = workWithDBProvider.CreateRestarauntAllData(Restaraunt, RestarauntLang); string tmp = String.Empty; foreach (var image in result.Images) // need debug. подумать как упростить { for (int i = image.Url.Length - 1; i >= 0; i--) { if (image.Url[i].Equals('\\')) { string NameAndExtension = new string(tmp.ToCharArray().Reverse().ToArray()); // gpj.<image_name> to <image_name>.jpg image.Url = image.Url.Remove(i + 1) + "small_" + NameAndExtension; tmp = string.Empty; break; } else { tmp += image.Url[i]; } } } return(Json(new { result = result })); } return(Json(new { result = "JSON is null" })); } catch { return(Json(new { result = "NaN" })); } }