public async Task <IActionResult> Land(LandAnnounceModel announce)
        {
            if (ModelState.IsValid)
            {
                announce.Paths = filesPaths;
                var t = await _announceToAdd.AddLand(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> AddLand(LandAnnounceModel announce)
        {
            try
            {
                DateTime addedDate = DateTime.Now;

                Land unicodeAnnounce = await _dbContext.Lands.FindAsync(_dbContext.Lands.Max(c => c.Id));

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

                Land land = new Land(announce.LandArea, announce.LandLocation)
                {
                    AnnounceAddedDate  = addedDate,
                    AnnounceTypeId     = announce.AnnounceTypeId,
                    Price              = announce.Price,
                    CityId             = announce.CityId,
                    Description        = announce.Description,
                    PersonTypeId       = announce.PersonTypeId,
                    Email              = announce.Email,
                    AnnounceUniqueCode = unicode,
                    PhoneNumber        = announce.PhoneNumber,
                };

                await _dbContext.Lands.AddAsync(land);

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


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