public ServiceResultModel <AttributeVM> UpdateAttribute(AttributeVM model) { using (EFBookingContext context = new EFBookingContext()) { var currentItem = context.Attributes.FirstOrDefault(p => p.Id == model.Id); if (currentItem != null) { if (context.Attributes.Any(p => p.Id != model.Id && (p.Name.Equals(model.Name) && p.AttributeType == model.AttributeType))) { return(new ServiceResultModel <AttributeVM> { Code = ServiceResultCode.Duplicate, Data = currentItem.MapToViewModel <AttributeVM>(), ResultType = OperationResultType.Warn, Message = "This title using other records " }); } currentItem.Name = model.Name; currentItem.Description = model.Description; context.Entry <Attributes>(currentItem).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(ServiceResultModel <AttributeVM> .OK(currentItem.MapToViewModel <AttributeVM>())); } }
public ServiceResultModel <RoomTypeVM> UpdateRoomType(RoomTypeVM model) { using (EFBookingContext context = new EFBookingContext()) { var currentItem = context.RoomTypes.FirstOrDefault(p => p.Id == model.Id); if (currentItem != null) { // mevcut kayıt haricinde title ile aynı kayıt olamaz kontrol ediyoruz if (context.RoomTypes.Any(p => p.Id != model.Id && p.Title.Equals(model.Title))) { return(new ServiceResultModel <RoomTypeVM> { Code = ServiceResultCode.Duplicate, Data = currentItem.MapToViewModel <RoomTypeVM>(), ResultType = OperationResultType.Warn, Message = "This title using other records " }); } currentItem.Title = model.Title; currentItem.Description = model.Description; context.Entry <RoomType>(currentItem).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(ServiceResultModel <RoomTypeVM> .OK(currentItem.MapToViewModel <RoomTypeVM>())); } }
public ServiceResultModel <HotelVM> UpdateHotel(HotelVM model) { using (EFBookingContext context = new EFBookingContext()) { var currentItem = context.Hotels.FirstOrDefault(p => p.Id == model.Id); if (currentItem != null) { if (context.Hotels.Any(p => p.Id != model.Id && p.Title.Equals(model.Title))) { return(new ServiceResultModel <HotelVM> { Code = ServiceResultCode.Duplicate, Data = currentItem.MapProperties <HotelVM>(), ResultType = OperationResultType.Warn, Message = "This title using other records " }); } currentItem.Title = model.Title; currentItem.HotelTypeId = model.HotelTypeId; context.Entry <Hotel>(currentItem).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(ServiceResultModel <HotelVM> .OK(currentItem.MapProperties <HotelVM>())); } }