public async Task <IActionResult> Job(JobAnnounceModel announce) { if (ModelState.IsValid) { announce.Paths = filesPaths; var t = await _announceToAdd.AddJob(announce); if (!t) { DeleteFile(filesPaths); } filesPaths.Clear(); return(RedirectToAction("Index", "Home")); } DeleteFile(filesPaths); return(View(await _dataFind.SettingDataAsync())); }
public async Task <bool> AddJob(JobAnnounceModel announce) { try { DateTime addedDate = DateTime.Now; Job unicodeAnnounce = await _dbContext.Jobs.FindAsync(_dbContext.Jobs.Max(c => c.Id)); string unicode = (Int32.Parse(unicodeAnnounce.AnnounceUniqueCode) + 1).ToString(); Job job = new Job { 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.JobName, ActivityAreaId = announce.JobActivityAreaId, AnnounceUniqueCode = unicode, JobTypeId = announce.JobTypeId, }; await _dbContext.Jobs.AddAsync(job); //car files upload start AddDataPhoto(announce.Paths, job.Id, "lib/images/jobs/job", FindTable.Job); //car files upload end await _dbContext.SaveChangesAsync(); } catch (Exception exp) { throw exp; } return(true); }