public async Task <IActionResult> SaveChangeInfo(RentCarCompany rentcarmodel) { var rccomp = _context.RentCarCompanies.Where(x => x.Id == rentcarmodel.Id).ToList().First(); rccomp.CompanyName = rentcarmodel.CompanyName; rccomp.Description = rentcarmodel.Description; rccomp.Adress = rentcarmodel.Adress; _context.Entry(rccomp).State = Microsoft.EntityFrameworkCore.EntityState.Modified; await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> AddingAdmin(AddAdmin userModel) { string role = User.Claims.ElementAt(1).Value; if (role != UserRole.SystemAdmin.ToString()) { return(BadRequest(new { message = "Bad data" })); } var applicationUser = new User() { UserName = userModel.AdminUsername, Email = userModel.Email, Name = "", Surname = "", PhoneNumber = "", Address = userModel.Address, }; //if (userModel.TypeOfCompany == "airline") //{ // Airline air = new Airline(); // air.Adress = userModel.Address; // air.Description = userModel.Description; // air.CompanyName = userModel.CompanyName; // applicationUser.Role = UserRole.AirlineAdmin; // try // { // var result = await _userManager.CreateAsync(applicationUser, userModel.Email); // var kk1 = await _userManager.FindByEmailAsync(userModel.Email); // kk1.AirlineComnpany = air; // _context.Entry(kk1).State = Microsoft.EntityFrameworkCore.EntityState.Modified; // await _context.SaveChangesAsync(); // return Ok(new { message = "Succesfuly added ! " }); // } // catch (Exception ex) // { // return BadRequest(new { Message = "Invalid Data" }); // throw ex; // } //} //else //{ RentCarCompany carC = new RentCarCompany(); carC.Adress = userModel.Address; carC.Description = userModel.Description; carC.CompanyName = userModel.CompanyName; applicationUser.Role = UserRole.CarAdmin; try { var result = await _userManager.CreateAsync(applicationUser, userModel.Email); var kk1 = await _userManager.FindByEmailAsync(userModel.Email); kk1.CarCompany = carC; _context.Entry(kk1).State = Microsoft.EntityFrameworkCore.EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(new { message = "Succesfuly added ! " })); } catch (Exception ex) { return(BadRequest(new { Message = "Invalid Data" })); throw ex; } //} }