public ActionResult Create(HouseCreateViewModel model)
        {
            //_context.RealtorHouses.Add(new RealtorHouse
            //{
            //    HouseId = model.Id,
            //    RealtorId = User.Identity.GetUserId()
            //});

            model.Name = "р-н" + model.DistrictName + ", вул." + model.StreetName;
            if (ModelState.IsValid)
            {
                _context.Houses.Add(new HouseModel
                {
                    Name         = model.Name,
                    DistrictName = model.DistrictName,
                    Parking      = model.Parking,
                    Picture      = model.Picture,
                    Price        = model.Price,
                    Repair       = model.Repair,
                    Square       = model.Square,
                    StreetName   = model.StreetName,
                    Warming      = model.Warming,
                    City         = model.City,
                    Floors       = model.Floors,
                    CountRooms   = model.CountRooms
                });
                _context.SaveChanges();

                return(RedirectToAction("List", "House"));
            }
            return(View(model));
        }
示例#2
0
        public IActionResult Create()
        {
            var model = new HouseCreateViewModel();

            ViewBag.OptionList   = _optionRepository.GetAll();
            ViewBag.CategoryList = _categoryRepository.GetAll();
            return(View(model));
        }
示例#3
0
        public ServiceResult <int> Create(HouseCreateViewModel model)
        {
            var entity = Mapper.Map <House>(model);

            _context.House.Add(entity);
            _context.SaveChanges();
            return(ServiceResult <int> .Okay(entity.Id));
        }
示例#4
0
        public IActionResult Create(HouseCreateViewModel model)
        {
            var userId = Convert.ToInt16(User.Identity.GetId());

            model.UserId        = userId;
            model.OptionIdsJson = JsonConvert.SerializeObject(model.OptionIds);
            if (string.IsNullOrEmpty(model.PhotoGalleryJson))
            {
                model.PhotoGalleryJson = "[]";
            }

            var result = _houseRepository.Create(model);

            TempData["Message"] = "آگهی شما با موفقیت ثبت و پس از بررسی بر روی سایت قرار میگیرد";
            return(RedirectToAction("Index"));
        }
示例#5
0
        //utility method
        private string ProcessUploadedFile(HouseCreateViewModel model)
        {
            string uniqueFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); //set path where to store
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;       //adding guid for uniqueness
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))             //this stream will copy file to it's path
                {
                    model.Photo.CopyTo(fileStream);
                }
                //it is properly disposed now via "using" statement
            }

            return(uniqueFileName);//if model has Photo unset => client hasn't set photo(default photo will be rendered)
        }
示例#6
0
        public IActionResult Create(HouseCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                //for file uploading
                string uniqueFileName = ProcessUploadedFile(model); //utility method for processing photo upload
                House  newHouse       = new House()                 //id is generated by ef core
                {
                    Address    = model.Address,
                    OwnerEmail = model.OwnerEmail,
                    Type       = model.Type,
                    Price      = model.Price,
                    PhotoPath  = uniqueFileName
                };

                _houseRepository.Add(newHouse);                                                              //this method generates id value
                return(RedirectToAction("details", new { id = protector.Protect(newHouse.Id.ToString()) })); //this statement redirects request to another action
            }

            return(View());//if ModelState is not valid view will render all errors
        }