public async Task <IActionResult> Office(OfficeAnnounceModel announce) { if (ModelState.IsValid) { announce.Paths = filesPaths; var t = await _announceToAdd.AddOffice(announce); if (!t) { DeleteFile(filesPaths); } filesPaths.Clear(); return(RedirectToAction("Index", "Home")); } DeleteFile(filesPaths); return(View(await _dataFind.SettingDataAsync())); }
public async Task <bool> AddOffice(OfficeAnnounceModel announce) { try { OfficeType officeType = await _dbContext.OfficeTypes.FindAsync(announce.OfficeTypeId); DateTime addedDate = DateTime.Now; Office unicodeAnnounce = await _dbContext.Offices.FindAsync(_dbContext.Offices.Max(c => c.Id)); string unicode = (Int32.Parse(unicodeAnnounce.AnnounceUniqueCode) + 1).ToString(); Office office = new Office(officeType, announce.OfficeLocation, 51) { 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, RSAnnounceTypeId = announce.OfficeRSAnnounceTypeId }; await _dbContext.Offices.AddAsync(office); //car files upload start AddDataPhoto(announce.Paths, office.Id, "lib/images/realestate/office", FindTable.Office); //car files upload end await _dbContext.SaveChangesAsync(); } catch (Exception exp) { throw exp; } return(true); }