public ActionResult Create(AddonModel model) { var currentHotelId = AppService.GetCurrentHotelId(); var hotel = HotelService.FindById(currentHotelId); var languages = new List<Language> { LanguageService.FindById((int)LanguageTypeEnum.English) }; var addon = Addon.Create(hotel, model.Price); for (var i = 0; i < languages.Count(); i++) { addon.Name.AddLocalizedText(model.Name[i].Value, languages[i]); addon.Description.AddLocalizedText(model.Description[i].Value, languages[i]); } addon.CalculationRule = model.SelectedCalculationRule; addon.PostingRhythm = model.SelectedPostingRhythm; hotel.Addons.Add(addon); HotelService.Save(hotel); var url = string.Format("/admin/addon/edit/{0}", addon.Id); return Json(new JsonResultSuccess("Created succesfully.", new { url = url, name = addon.Name.GetText(LanguageTypeEnum.English), created = true })); }
public ActionResult Edit(AddonModel model) { var currentHotelId = AppService.GetCurrentHotelId(); var addons = AddonService.FindAllByHotelId(currentHotelId); var languages = new List<Language> { LanguageService.FindById((int)LanguageTypeEnum.English) }; var addon = addons.Where(x => x.Id == model.Id).FirstOrDefault(); if (addon == null) { throw new ApplicationException("Addon could not be found."); } for (var i = 0; i < languages.Count(); i++) { addon.Name.AddLocalizedText(model.Name[i].Value, languages[i]); addon.Description.AddLocalizedText(model.Description[i].Value, languages[i]); } addon.Price = model.Price; addon.CalculationRule = model.SelectedCalculationRule; addon.PostingRhythm = model.SelectedPostingRhythm; AddonService.Save(addon); return Json(new JsonResultSuccess("Updated succesfully.")); }