public ActionResult Create() { var model = new HotelCreateModel() { Boss = new BossCreateModel() }; return(View(model)); }
public IActionResult Create([FromBody] HotelCreateModel model, string merchantId) { var merchantIdDecrypted = Decrypt.DecryptToInt32(merchantId); if (merchantIdDecrypted != 0) { model.MerchantFid = merchantIdDecrypted; var response = _hotelService.Setup(model); return(Ok(response)); } return(Ok(BaseResponse <bool> .BadRequest())); }
public IActionResult CreateHotel([FromBody] HotelCreateModel model) { // map model to entity var hotel = _mapper.Map <Hotel>(model); var currentUserId = int.Parse(User.Identity.Name); try { // create user _hotelService.Create(hotel, currentUserId); return(Ok($"You have created successfully a hotel. \n Name: {hotel.Name} ")); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public BaseResponse <int> Create(HotelCreateModel model) { try { //Return badRequest if model null if (model == null) { return(BaseResponse <int> .BadRequest()); } //Convert model to hotel var entity = _mapper.Map <HotelCreateModel, Hotels>(model); var now = DateTime.Now.Date; var userId = UserContextHelper.UserId; //Generate private properties for hotel entity.UniqueId = UniqueIDHelper.GenarateRandomString(12); entity.Deleted = false; entity.ActiveForOperation = false; entity.CreatedDate = now; entity.LastModifiedDate = now; entity.CreatedBy = userId; entity.LastModifiedBy = userId; //Load Res Keys entity.StatusResKey = _commonValueRequestService.Find(entity.StatusFid)?.ResponseData?.ResourceKey; entity.HotelTypeResKey = _commonValueRequestService.Find(entity.HotelTypeFid)?.ResponseData?.ResourceKey; entity.HotelCategoryResKey = _commonValueRequestService.Find(entity.HotelCategoryFid)?.ResponseData?.ResourceKey; //Insert to database and return success _db.Hotels.Add(entity); _db.SaveChanges(); return(BaseResponse <int> .Success(entity.Id)); } catch (Exception ex) { return(BaseResponse <int> .InternalServerError(ex)); } }
public ActionResult Create(HotelCreateModel model) { bool allEmpty = string.IsNullOrEmpty(model.Boss?.FirstName) && string.IsNullOrEmpty(model.Boss?.SecondName) && string.IsNullOrEmpty(model.Boss?.MiddleName) && string.IsNullOrEmpty(model.Boss?.IndividualId); bool allFilled = !string.IsNullOrEmpty(model.Boss?.FirstName) && !string.IsNullOrEmpty(model.Boss.SecondName) && !string.IsNullOrEmpty(model.Boss.MiddleName) && !string.IsNullOrEmpty(model.Boss.IndividualId); if (!allEmpty && !allFilled) { return(View(model)); } if (ModelState.IsValid) { var hotel = _hotelCreateCommand.Execute(model); return(RedirectToAction("Details", new { id = hotel.Id })); } return(View(model)); }
public BaseResponse <bool> Setup(HotelCreateModel model) { using (var transaction = _db.Database.BeginTransaction()) { try { var createHotelResult = Create(model); if (createHotelResult.IsSuccessStatusCode) { var hotelId = createHotelResult.ResponseData; var attributeCreateString = model.HotelAttributesCreateString; var listAtts = attributeCreateString.Split(","); var listAttributetoCreates = listAtts.Select(k => new HotelAttributeValueCreateModels() { HotelFid = hotelId, AttributeFid = k.Split("_")[0].ToInt32(), AttributeValue = k.Split("_")[1] }).ToList(); var createAttributeResult = _hotelAttributeValueService.CreateRangeAsync(listAttributetoCreates).Result; transaction.Commit(); return(BaseResponse <bool> .Success(true)); } transaction.Rollback(); return(BaseResponse <bool> .BadRequest()); } catch (Exception ex) { transaction.Rollback(); return(BaseResponse <bool> .InternalServerError(ex)); } } }