Esempio n. 1
0
        public JsonResult SaveHotel(HotelVM model)
        {
            if (!ModelState.IsValid)
            {
                return(base.JSonModelStateHandle());
            }

            ServiceResultModel <HotelVM> serviceResult = _hotelService.SaveHotel(model);

            if (!serviceResult.IsSuccess)
            {
                base.UIResponse = new UIResponse
                {
                    Message    = string.Format("Operation Is Not Completed, {0}", serviceResult.Message),
                    ResultType = serviceResult.ResultType,
                    Data       = serviceResult.Data
                };
            }
            else
            {
                base.UIResponse = new UIResponse
                {
                    Data       = serviceResult.Data,
                    ResultType = serviceResult.ResultType,
                    Message    = "Success"
                };
            }

            return(Json(base.UIResponse, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public IActionResult Edit(long id)
        {
            Hotel hotel = this.db.Hoteis
                          .Include(m => m.Cidade)
                          .Where(x => x.Id == id)
                          .FirstOrDefault();

            if (hotel == null)
            {
                return(NotFound());
            }

            HotelVM vm = new HotelVM();

            vm.Nome      = hotel.Nome;
            vm.Descricao = hotel.Descricao;
            vm.Preco     = hotel.Preco;
            var cidades = db.Cidades.ToList();

            foreach (var cidade in cidades)
            {
                vm.Cidades.Add(new SelectListItem
                {
                    Value = cidade.Id.ToString(),
                    Text  = cidade.Nome
                });
            }
            vm.IdCidadeSelecionada = hotel.Cidade.Id;

            return(View(vm));
        }
        public async Task <HotelVM> GetHotelsAsync(int pageno, int pagesize, string sterm)
        {
            HotelVM model    = new HotelVM();
            var     parStart = new SqlParameter("@Start", (pageno - 1) * pagesize);
            var     parEnd   = new SqlParameter("@PageSize", pagesize);

            var parSearchTerm = new SqlParameter("@SearchTerm", DBNull.Value);

            if (!(sterm == null || sterm == ""))
            {
                parSearchTerm.Value = sterm;
            }
            // setting stored procedure OUTPUT value
            // This return total number of rows, and avoid two database call for data and total number of rows
            var spOutput = new SqlParameter
            {
                ParameterName = "@TotalCount",
                SqlDbType     = System.Data.SqlDbType.BigInt,
                Direction     = System.Data.ParameterDirection.Output
            };

            model.Hotels = await db.Database.SqlQuery <HotelView>("udspMstHotelPaged @Start, @PageSize,@SearchTerm, @TotalCount out",
                                                                  parStart, parEnd, parSearchTerm, spOutput).ToListAsync();

            model.TotalRecords = int.Parse(spOutput.Value.ToString());
            return(model);
        }
Esempio n. 4
0
        public JsonResult UpdateHotel(HotelVM model)
        {
            if (model.Id <= 0)
            {
                RedirectToAction(nameof(HotelList)); // ErrorHandle eklenecek
            }
            if (!ModelState.IsValid)
            {
                return(base.JSonModelStateHandle());
            }

            ServiceResultModel <HotelVM> serviceResult = _hotelService.UpdateHotel(model);

            if (!serviceResult.IsSuccess)
            {
                base.UIResponse = new UIResponse
                {
                    Message    = string.Format("Operation Is Not Completed, {0}", serviceResult.Message),
                    ResultType = serviceResult.ResultType,
                    Data       = serviceResult.Data
                };
            }
            else
            {
                base.UIResponse = new UIResponse
                {
                    Data       = serviceResult.Data,
                    ResultType = serviceResult.ResultType,
                    Message    = "Success"
                };
            }

            return(Json(base.UIResponse, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public ServiceResultModel <HotelVM> UpdateHotel(HotelVM model)
        {
            using (EFBookingContext context = new EFBookingContext())
            {
                var currentItem = context.Hotels.FirstOrDefault(p => p.Id == model.Id);
                if (currentItem != null)
                {
                    if (context.Hotels.Any(p => p.Id != model.Id && p.Title.Equals(model.Title)))
                    {
                        return(new ServiceResultModel <HotelVM>
                        {
                            Code = ServiceResultCode.Duplicate,
                            Data = currentItem.MapProperties <HotelVM>(),
                            ResultType = OperationResultType.Warn,
                            Message = "This title using other records "
                        });
                    }
                    currentItem.Title = model.Title;

                    currentItem.HotelTypeId = model.HotelTypeId;

                    context.Entry <Hotel>(currentItem).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }

                return(ServiceResultModel <HotelVM> .OK(currentItem.MapProperties <HotelVM>()));
            }
        }
Esempio n. 6
0
        public IActionResult Create(HotelVM vm)
        {
            if (ModelState.IsValid)
            {
                Hotel hotel = new Hotel();
                hotel.Nome          = vm.Nome;
                hotel.Descricao     = vm.Descricao;
                hotel.Preco         = vm.Preco;
                hotel.CaminhoImagem = this.UploadImagem(vm.Imagem);
                hotel.Cidade        = db.Cidades.Find(vm.IdCidadeSelecionada);
                hotel.Suite         = db.Suites.Find(vm.IdSuiteSelecionada);
                hotel.Gastronomia   = db.Gastronomias.Find(vm.IdGastronomiaSelecionada);
                this.db.Hoteis.Add(hotel);
                this.db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var cidades = db.Cidades.ToList();

            foreach (var cidade in cidades)
            {
                vm.Cidades.Add(new SelectListItem
                {
                    Value = cidade.Id.ToString(),
                    Text  = cidade.Nome
                });
            }

            var suites = db.Suites.ToList();

            foreach (var suite in suites)
            {
                vm.Suites.Add(new SelectListItem
                {
                    Value = suite.Id.ToString(),
                    Text  = suite.Tipo
                });
            }

            var gastronomias = db.Gastronomias.ToList();

            foreach (var gastronomia in gastronomias)
            {
                vm.Gastronomias.Add(new SelectListItem
                {
                    Value = gastronomia.Id.ToString(),
                    Text  = gastronomia.Nome
                });
            }

            return(View(vm));
        }
Esempio n. 7
0
        public async Task <ActionResult <HotelVM> > GetHotel(int id)
        {
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString =
                "Server=localhost;Database=PaymentDetailDB;Trusted_Connection=True;MultipleActiveResultSets=True;";

            connection.Open();
            string procedureName = "[dbo].[GetHotels]";
            var    result        = new List <HotelVM>();

            using (SqlCommand command = new SqlCommand(procedureName, connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@HotelId", id));

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int     HotelId     = int.Parse(reader[0].ToString());
                        string  HotelName   = reader[1].ToString();
                        int     CityId      = int.Parse(reader[2]?.ToString());
                        string? Address     = reader[3].ToString();
                        string? Description = reader[4].ToString();
                        string  CityName    = reader[5]?.ToString();
                        int     CountryId   = int.Parse(reader[6]?.ToString());
                        string  CountryName = reader[7]?.ToString();
                        HotelVM tmpRecord   = new HotelVM()
                        {
                            HotelId     = HotelId,
                            HotelName   = HotelName,
                            CityId      = CityId,
                            Adddress    = Address,
                            Description = Description,
                            CityName    = CityName,
                            CountryID   = CountryId,
                            CountryName = CountryName
                        };
                        result.Add(tmpRecord);
                    }
                }
            }


            if (result == null)
            {
                return(NotFound());
            }

            return(result.FirstOrDefault());
        }
Esempio n. 8
0
        public ServiceResultModel <HotelVM> GetHotel(int id)
        {
            if (id <= 0)
            {
                return(null);
            }
            HotelVM currentItem = null;

            using (EFBookingContext context = new EFBookingContext())
            {
                currentItem = context.Hotels.FirstOrDefault(p => p.Id == id).MapProperties <HotelVM>();
            }

            return(ServiceResultModel <HotelVM> .OK(currentItem));
        }
Esempio n. 9
0
        public IActionResult Edit(long id, HotelVM vm)
        {
            if (ModelState.IsValid)
            {
                Hotel hotelDb = this.db.Hoteis.Find(id);
                hotelDb.Nome          = vm.Nome;
                hotelDb.Descricao     = vm.Descricao;
                hotelDb.Preco         = vm.Preco;
                hotelDb.CaminhoImagem = this.UploadImagem(vm.Imagem);
                hotelDb.Cidade        = db.Cidades.Find(vm.IdCidadeSelecionada);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vm));
        }
Esempio n. 10
0
        public HttpResponseMessage Post([FromBody] HotelVM HotelObject)
        {
            try
            {
                HotelObject.CreatedDate = DateTime.Today;
                HotelObject.UpdatedDate = DateTime.Today;
                int id = _hotelBL.PostHotel(HotelObject);

                var message = Request.CreateResponse(HttpStatusCode.Created, HotelObject);
                message.Headers.Location = new Uri(Request.RequestUri + id.ToString());
                return(message);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Esempio n. 11
0
        public int PostHotel(HotelVM HotelObject)
        {
            using (var context = new DbWebAPIEntities())
            {
                //Create Mapper configuration
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap <HotelVM, tblHotel>();
                });

                //Map the objects
                var      mapper = new Mapper(config);
                tblHotel record = mapper.Map <HotelVM, tblHotel>(HotelObject);
                context.tblHotels.Add(record);
                context.SaveChanges();

                return(record.HotelId);
            }
        }
Esempio n. 12
0
        public IActionResult Create()
        {
            HotelVM vm = new HotelVM();

            var cidades = db.Cidades.ToList();

            foreach (var cidade in cidades)
            {
                vm.Cidades.Add(new SelectListItem
                {
                    Value = cidade.Id.ToString(),
                    Text  = cidade.Nome
                });
            }

            var suites = db.Suites.ToList();

            foreach (var suite in suites)
            {
                vm.Suites.Add(new SelectListItem
                {
                    Value = suite.Id.ToString(),
                    Text  = suite.Tipo
                });
            }

            var gastronomias = db.Gastronomias.ToList();

            foreach (var gastronomia in gastronomias)
            {
                vm.Gastronomias.Add(new SelectListItem
                {
                    Value = gastronomia.Id.ToString(),
                    Text  = gastronomia.Nome
                });
            }

            return(View(vm));
        }
Esempio n. 13
0
 public ActionResult Index(int PageNo = 1, int PageSize = 10, string SearchTerm = "")
 {
     try
     {
         string     query    = "PageNo=" + PageNo + "&PageSize=" + PageSize + "&SearchTerm=" + SearchTerm;
         HotelAPIVM apiModel = objAPI.GetRecordByQueryString <HotelAPIVM>("hotelconfig", "hotels", query);
         HotelVM    model    = new HotelVM();
         model.Hotels     = apiModel.Hotels;
         model.PagingInfo = new PagingInfo {
             CurrentPage = PageNo, ItemsPerPage = PageSize, TotalItems = apiModel.TotalRecords
         };
         if (Request.IsAjaxRequest())
         {
             return(PartialView("_pvHotelList", model));
         }
         return(View(model));
     }
     catch (AuthorizationException)
     {
         TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again";
         return(RedirectToAction("Login", "Account", new { Area = "" }));
     }
 }
Esempio n. 14
0
        public ServiceResultModel <HotelVM> SaveHotel(HotelVM model)
        {
            using (EFBookingContext context = new EFBookingContext())
            {
                bool isAlreadyExists = context.Hotels.Any(p => p.Title == model.Title);
                if (isAlreadyExists)
                {
                    return new ServiceResultModel <HotelVM>
                           {
                               Code       = ServiceResultCode.Duplicate,
                               Data       = null,
                               ResultType = OperationResultType.Warn,
                               Message    = "This record already exists"
                           }
                }
                ;

                var recordItem = context.Hotels.Add(model.MapProperties <Hotel>());
                context.SaveChanges();

                return(ServiceResultModel <HotelVM> .OK(recordItem.MapProperties <HotelVM>()));
            }
        }
 public HotelHandler(HotelVM hotelVm)
 {
     _hotelVm  = hotelVm;
     _consumer = _hotelVm.ConsumerHotel;
 }
Esempio n. 16
0
        public int PostHotel(HotelVM HotelObject)
        {
            int id = HotelDAL.PostHotel(HotelObject);

            return(id);
        }