public async Task <bool> CreateRoomType(RoomTypeServiceModel roomTypeServiceModel) { var roomTypeFromDb = await context.RoomTypes.SingleOrDefaultAsync(x => x.Name == roomTypeServiceModel.Name); if (roomTypeFromDb != null) { roomTypeFromDb.Name = roomTypeServiceModel.Name; roomTypeFromDb.PriceForBed = roomTypeServiceModel.PriceForBed; roomTypeFromDb.IsDeleted = false; roomTypeFromDb.DeletedOn = null; context.RoomTypes.Update(roomTypeFromDb); int result = await context.SaveChangesAsync(); return(result > 0); } else { RoomType roomType = AutoMapper.Mapper.Map <RoomType>(roomTypeServiceModel); context.RoomTypes.Add(roomType); int result = await context.SaveChangesAsync(); return(result > 0); } }
public async Task <IActionResult> Edit(int id, RoomTypeEditInputModel roomTypeEditInputModel) { if (!ModelState.IsValid) { return(View(roomTypeEditInputModel)); } RoomTypeServiceModel roomTypeServiceModel = AutoMapper.Mapper.Map <RoomTypeServiceModel>(roomTypeEditInputModel); await roomTypeService.Edit(id, roomTypeServiceModel); return(Redirect("/Administration/RoomType/All")); }
public async Task <bool> Edit(int id, RoomTypeServiceModel roomTypeServiceModel) { RoomType roomTypeFromDb = await context.RoomTypes.SingleOrDefaultAsync(roomType => roomType.Id == id); if (roomTypeFromDb == null) { throw new ArgumentNullException(nameof(roomTypeFromDb)); } roomTypeFromDb.Name = roomTypeServiceModel.Name; roomTypeFromDb.PriceForBed = roomTypeServiceModel.PriceForBed; context.RoomTypes.Update(roomTypeFromDb); int result = await context.SaveChangesAsync(); return(result > 0); }