Ejemplo n.º 1
0
 public bool Add(Hotel hotel)
 {
     bool result = true;
     try
     {
         context.Hotels.Add(hotel);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         var code = ex.HResult;
         result = false;
     }
     return result;
 }
Ejemplo n.º 2
0
        public ActionResult AddHotelForm(Hotel hotel)
        {
            ErrorModel result = new ErrorModel
            {
                Error = false,
                ErrorText = ""
            };
            if (hotel.Id_City == null)
            {
                result.Error = true;
                result.ErrorText = "Город не указан";
                return Json(result);
            }
            if (hotel.Name == null)
            {
                result.Error = true;
                result.ErrorText = "Название отеля не указано";
                return Json(result);
            }
            if (!hotelRepository.Add(hotel))
            {
                result.Error = true;
                result.ErrorText = "Возможно такой отель уже существует";
            }

            return Json(result);
        }