public static async Task <bool> Update(Guid token, Models.Cars.Car car) { var userInfo = AuthenticationLogic.CheckTokenInfo(token); using (var db = new DataAccess.CaraxEntitiy()) { car.UpdatedDateTime = DateTime.Now; car.UpdatedBy = userInfo.Username; car.CompanyCode = userInfo.CompanyCode; car.DepartmentCode = userInfo.DepartmentCode; db.Cars.Update(car); return(await db.SaveChangesAsync() > 0); } }
public static async Task <bool> Add(Guid token, string departmentCode, Models.Cars.Car car) { var userInfo = AuthenticationLogic.CheckTokenInfo(token); car.CreatedDateTime = DateTime.Now; car.CreatedBy = userInfo.Username; car.CompanyCode = userInfo.CompanyCode; car.DepartmentCode = departmentCode; using (var db = new DataAccess.CaraxEntitiy()) { var isExistCar = await db.Cars.AnyAsync(q => q.Plate.ReplaceCarPlate().Contains(car.Plate.ReplaceCarPlate())); if (isExistCar) { return(false); } db.Cars.Add(car); return(await db.SaveChangesAsync() > 0); } }
public async Task <IActionResult> Update(Models.Cars.Car car) { var isSuccess = await CarLogic.Update(GetToken(), car); return(Ok(isSuccess)); }
public async Task <IActionResult> Create([FromBody] Models.Cars.Car car) { var isSuccess = await CarLogic.Add(GetToken(), GetDepartmentCode(), car); return(Ok(isSuccess)); }