public ServiceResultModel <HotelTypeVM> UpdateHotelType(HotelTypeVM model)
        {
            using (EFBookingContext context = new EFBookingContext())
            {
                var currentItem = context.HotelTypes.FirstOrDefault(p => p.Id == model.Id);
                if (currentItem != null)
                {
                    // mevcut kayıt haricinde title ile aynı kayıt olamaz kontrol ediyoruz
                    if (context.HotelTypes.Any(p => p.Id != model.Id && p.Title.Equals(model.Title)))
                    {
                        return(new ServiceResultModel <HotelTypeVM>
                        {
                            Code = ServiceResultCode.Duplicate,
                            Data = currentItem.MapToViewModel <HotelTypeVM>(),
                            ResultType = OperationResultType.Warn,
                            Message = "This title using other records "
                        });
                    }
                    currentItem.Title       = model.Title;
                    currentItem.Description = model.Description;

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

                return(ServiceResultModel <HotelTypeVM> .OK(currentItem.MapToViewModel <HotelTypeVM>()));
            }
        }
Beispiel #2
0
        public JsonResult SaveHotelType(HotelTypeVM model)
        {
            if (!ModelState.IsValid)
            {
                return(base.JSonModelStateHandle());
            }

            ServiceResultModel <HotelTypeVM> serviceResult = _hotelTypeService.SaveHotelType(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));
        }
Beispiel #3
0
        public JsonResult UpdateHotelType(HotelTypeVM model)
        {
            if (model.Id <= 0)
            {
                RedirectToAction(nameof(HotelTypeList)); // ErrorHandle eklenecek
            }

            if (!ModelState.IsValid)
            {
                return(base.JSonModelStateHandle());
            }

            ServiceResultModel <HotelTypeVM> serviceResult = _hotelTypeService.UpdateHotelType(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));
        }
        public ServiceResultModel <HotelTypeVM> GetHotelType(int id)
        {
            if (id <= 0)
            {
                return(null);
            }
            HotelTypeVM currentItem = null;

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

            return(ServiceResultModel <HotelTypeVM> .OK(currentItem));
        }
        public ServiceResultModel <HotelTypeVM> SaveHotelType(HotelTypeVM model)
        {
            using (EFBookingContext context = new EFBookingContext())
            {
                bool isAlreadyExists = context.HotelTypes.Any(p => p.Title == model.Title);
                if (isAlreadyExists)
                {
                    return(new ServiceResultModel <HotelTypeVM>
                    {
                        Code = ServiceResultCode.Duplicate,
                        Data = null,
                        ResultType = OperationResultType.Warn,
                        Message = "This record already exists"
                    });
                }

                var recordItem = context.HotelTypes.Add(model.MapToEntityModel <HotelType>());
                context.SaveChanges();

                return(ServiceResultModel <HotelTypeVM> .OK(recordItem.MapToViewModel <HotelTypeVM>()));
            }
        }