public async Task <bool> AddBus(BusAnnounceModel announce) { try { BusBodyType bodyType = await _dbContext.BusBodyTypes.FindAsync(announce.BusBodyTypeId); DateTime addedDate = DateTime.Now; Bus unicodeAnnounce = await _dbContext.Buses.FindAsync(_dbContext.Buses.Max(c => c.Id)); string unicode = (Int32.Parse(unicodeAnnounce.AnnounceUniqueCode) + 1).ToString(); Bus bus = new Bus(bodyType, announce.BusYear) { AnnounceAddedDate = addedDate, AnnounceTypeId = announce.AnnounceTypeId, Price = announce.Price, CityId = announce.CityId, Description = announce.Description, PersonTypeId = announce.PersonTypeId, Email = announce.Email, PhoneNumber = announce.PhoneNumber, BusKilometer = announce.BusKilometer, BusMakeId = announce.BusMakeId, Condition = announce.BusCondition, AnnounceUniqueCode = unicode, }; await _dbContext.Buses.AddAsync(bus); //car files upload start AddDataPhoto(announce.Paths, bus.Id, "lib/images/transport/car", FindTable.Bus); //car files upload end await _dbContext.SaveChangesAsync(); } catch (Exception exp) { throw exp; } return(true); }
public async Task <IActionResult> AddBusBodyType(string name) { if (!String.IsNullOrEmpty(name)) { try { var busBody = new BusBodyType { Name = name, }; await _dbContext.BusBodyTypes.AddAsync(busBody); await _dbContext.SaveChangesAsync(); return(Json(busBody)); } catch (Exception) { return(Json("fail")); } } return(Json("fail")); }