public async Task <IActionResult> House(HouseAnnounceModel announce)
        {
            if (ModelState.IsValid)
            {
                announce.Paths = filesPaths;
                var t = await _announceToAdd.AddHouse(announce);

                if (!t)
                {
                    DeleteFile(filesPaths);
                }
                filesPaths.Clear();
                return(RedirectToAction("Index", "Home"));
            }
            DeleteFile(filesPaths);
            return(View(await _dataFind.SettingDataAsync()));
        }
Example #2
0
        public async Task <bool> AddHouse(HouseAnnounceModel announce)
        {
            try
            {
                HouseType houseType = await _dbContext.HouseTypes.FindAsync(announce.HouseTypeId);

                DateTime addedDate = DateTime.Now;

                House unicodeAnnounce = await _dbContext.Houses.FindAsync(_dbContext.Houses.Max(c => c.Id));

                string unicode = (Int32.Parse(unicodeAnnounce.AnnounceUniqueCode) + 1).ToString();

                House house = new House(houseType, announce.HouseLocation)
                {
                    AnnounceAddedDate  = addedDate,
                    AnnounceTypeId     = announce.AnnounceTypeId,
                    Price              = announce.Price,
                    CityId             = announce.CityId,
                    Description        = announce.Description,
                    PersonTypeId       = announce.PersonTypeId,
                    Email              = announce.Email,
                    PhoneNumber        = announce.PhoneNumber,
                    AnnounceUniqueCode = unicode,
                    RSAnnounceTypeId   = announce.HouseRSAnnounceTypeId,
                };

                await _dbContext.Houses.AddAsync(house);

                //car files upload start
                AddDataPhoto(announce.Paths, house.Id, "lib/images/realestate/house", FindTable.House);


                //car files upload end
                await _dbContext.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return(true);
        }