public async Task <IActionResult> Business(BusinessAnnounceModel announce) { if (ModelState.IsValid) { announce.Paths = filesPaths; var t = await _announceToAdd.AddBuisness(announce); if (!t) { DeleteFile(filesPaths); } filesPaths.Clear(); return(RedirectToAction("Index", "Home")); } DeleteFile(filesPaths); return(View(await _dataFind.SettingDataAsync())); }
public async Task <bool> AddBuisness(BusinessAnnounceModel announce) { try { DateTime addedDate = DateTime.Now; BusinessEquipment unicodeAnnounce = await _dbContext.BusinessEquipments.FindAsync(_dbContext.BusinessEquipments.Max(c => c.Id)); string unicode = (Int32.Parse(unicodeAnnounce.AnnounceUniqueCode) + 1).ToString(); BusinessEquipment businessEquipment = new BusinessEquipment { AnnounceAddedDate = addedDate, AnnounceTypeId = announce.AnnounceTypeId, Price = announce.Price, CityId = announce.CityId, Description = announce.Description, PersonTypeId = announce.PersonTypeId, Email = announce.Email, PhoneNumber = announce.PhoneNumber, AnnounceName = announce.BusinessName, BusinessTypeId = announce.BusinessTypeId, AnnounceUniqueCode = unicode, }; await _dbContext.BusinessEquipments.AddAsync(businessEquipment); //car files upload start AddDataPhoto(announce.Paths, businessEquipment.Id, "lib/images/jobs/business", FindTable.Business); //car files upload end await _dbContext.SaveChangesAsync(); } catch (Exception exp) { throw exp; } return(true); }