public async Task <IActionResult> Qarage(QarageAnnounceModel announce)
        {
            if (ModelState.IsValid)
            {
                announce.Paths = filesPaths;
                var t = await _announceToAdd.AddQarage(announce);

                if (!t)
                {
                    DeleteFile(filesPaths);
                }
                filesPaths.Clear();
                return(RedirectToAction("Index", "Home"));
            }
            DeleteFile(filesPaths);
            return(View(await _dataFind.SettingDataAsync()));
        }
Exemple #2
0
        public async Task <bool> AddQarage(QarageAnnounceModel announce)
        {
            try
            {
                DateTime addedDate = DateTime.Now;

                Garage unicodeAnnounce = await _dbContext.Garages.FindAsync(_dbContext.Garages.Max(c => c.Id));

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

                Garage garage = new Garage
                {
                    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,
                    AnnounceName       = announce.GarageName,
                    GarageLocation     = announce.GarageLocation
                };


                await _dbContext.Garages.AddAsync(garage);

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


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