Exemplo n.º 1
0
        public async Task <IActionResult> Create(PlaceCreateModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            await _service.Create(model, user.Id);

            return(RedirectToAction("GetAll"));
        }
Exemplo n.º 2
0
        public async Task Create(PlaceCreateModel model, string userId)
        {
            var place = _mapper.Map <Place>(model);

            place.UserId = userId;
            var entity = await _context.AddAsync(place);

            await CreatePhotos(model.Images, entity.Entity.Id);
        }
Exemplo n.º 3
0
        //[HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        //public ActionResult Delete_Confirm(int id)
        //{
        //    var strError = string.Empty;
        //    if (id <= 0)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }

        //    try
        //    {
        //        _mainStore.Delete(id);
        //        //Clear cache
        //        PlaceServices.ClearPlaceCache();
        //    }
        //    catch (Exception ex)
        //    {
        //        strError = ManagerResource.LB_SYSTEM_BUSY;

        //        logger.Error("Failed to get Delete Place because: " + ex.ToString());

        //        return Json(new { success = false, message = strError });
        //    }

        //    return Json(new { success = true, message = ManagerResource.LB_DELETE_SUCCESS, title = ManagerResource.LB_NOTIFICATION });
        //}

        #region Helpers

        private IdentityPlace ExtractCreateFormData(PlaceCreateModel formData)
        {
            var myIdetity = new IdentityPlace();

            //myIdetity.Name = formData.Name;
            //myIdetity.Code = formData.Code;
            //myIdetity.UrlFriendly = UrlFriendly.ConvertToUrlFriendly(formData.Name);
            //myIdetity.Icon = formData.Icon;
            //myIdetity.Status = Utils.ConvertToInt32(formData.Status);
            //myIdetity.CreatedBy = User.Identity.GetUserId();

            return(myIdetity);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PostPlace([FromBody] PlaceCreateModel model)
        {
            var place = await Mediator.Send(Mapper.Map <CommandCreatePlace>(model));

            return(Ok(new { place.Id }));
        }
Exemplo n.º 5
0
        public async Task <object> Create(PlaceCreateModel plc)
        {
            #region CheckModelIsInvalid
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            #endregion

            #region CheckUserIsNull
            if (!await _context.Users.AnyAsync(u => u.Id == User.GetUserId()))
            {
                return(NotFound());
            }
            #endregion

            plc.Place.UserId   = User.GetUserId();
            plc.Place.CreateAt = DateTime.UtcNow.AddHours(4);
            Place place = new Place();

            /*Try to photo upload,add to context and savecAhnges*/
            try
            {
                if (!string.IsNullOrWhiteSpace(plc.Place.Photo) && !string.IsNullOrWhiteSpace(plc.Place.PhotoFileName))
                {
                    plc.Place.Photo = FileManager.Upload(plc.Place.Photo, plc.Place.PhotoFileName);
                }

                place = _mapper.Map <Place>(plc.Place);
                await _context.Places.AddAsync(place);

                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(StatusCode(409));
            }

            /*Create PlaceTags*/
            if (plc.Tags != null && plc.Tags.Count > 0)
            {
                foreach (var tag in plc.Tags)
                {
                    #region CehckTagsNull
                    if (!await _context.Tags.AnyAsync(t => t.Id == tag.Id))
                    {
                        continue;
                    }
                    #endregion

                    PlacesTags placeTag = new PlacesTags
                    {
                        TagId   = tag.Id,
                        PlaceId = place.Id
                    };

                    //PlaceTags add to context
                    try
                    {
                        await _context.PlacesTags.AddAsync(placeTag);

                        await _context.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

            /*Create PlaceTags*/
            if (plc.Socials != null && plc.Socials.Count > 0)
            {
                foreach (var social in plc.Socials)
                {
                    #region CehckSocialIsEmpty
                    if (string.IsNullOrWhiteSpace(social.Link) || string.IsNullOrWhiteSpace(social.Name))
                    {
                        continue;
                    }
                    #endregion

                    Social soc = new Social
                    {
                        Link    = social.Link,
                        Name    = social.Name,
                        PlaceId = place.Id,
                        Type    = SocialType.Place
                    };

                    //Social add to context
                    try
                    {
                        await _context.Socials.AddAsync(soc);

                        await _context.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

            /*Create Slider Photos*/
            if (plc.SliderPhotos != null && plc.SliderPhotos.Count > 0)
            {
                foreach (var slider in plc.SliderPhotos)
                {
                    #region CehckSliderIsEmpty
                    if (string.IsNullOrWhiteSpace(slider.Photo) || string.IsNullOrWhiteSpace(slider.PhotoName))
                    {
                        continue;
                    }
                    #endregion

                    PlaceSliderPhotos photo = new PlaceSliderPhotos();
                    photo.PlaceId = place.Id;
                    try
                    {
                        photo.Photo     = FileManager.Upload(slider.Photo, slider.PhotoName);
                        photo.PhotoName = slider.PhotoName;

                        await _context.PlaceSliderPhotos.AddAsync(photo);

                        await _context.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

            /*Create PlaceFaqs*/
            if (plc.Faqs != null && plc.Faqs.Count > 0)
            {
                foreach (var faq in plc.Faqs)
                {
                    #region CehckFaqIsEmpty
                    if (string.IsNullOrWhiteSpace(faq.Answer) || string.IsNullOrWhiteSpace(faq.Question))
                    {
                        continue;
                    }
                    #endregion

                    PlaceFaq newFaq = new PlaceFaq
                    {
                        Answer   = faq.Answer,
                        Question = faq.Question,
                        PlaceId  = place.Id
                    };

                    //Faq add to context
                    try
                    {
                        await _context.PlaceFaqs.AddAsync(newFaq);

                        await _context.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

            /*Create WorkHours*/
            if (plc.WorkHours != null && plc.WorkHours.Count > 0)
            {
                foreach (var hour in plc.WorkHours)
                {
                    WorkHour workHour = new WorkHour
                    {
                        Day     = hour.Day,
                        Open    = hour.Open,
                        Close   = hour.Close,
                        PlaceId = place.Id
                    };

                    //WorkHour add to context
                    try
                    {
                        await _context.WorkHours.AddAsync(workHour);

                        await _context.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

            return(StatusCode(201));
        }