public string UpdateFlat(FlatModel flat) { Mapper.CreateMap <FlatModel, Flat>().ForMember(dest => dest.FlatPLCs, sec => sec.Ignore()); Flat fl = Mapper.Map <FlatModel, Flat>(flat); int i = fservice.EditFlat(fl); FlatPLCService fpservice = new FlatPLCService(); var model = fpservice.GetFlatPLCListByFlatID(fl.FlatID); foreach (var ft in model) { FlatPLC md = new FlatPLC(); md.FlatPLCID = ft.FlatPLCID; int ii = fpservice.DeleteFlatPLC(md); } foreach (string st in flat.FlatPLCs) { if (st != "0") { FlatPLC fpm = new FlatPLC(); fpm.FlatID = fl.FlatID; fpm.PLCID = Convert.ToInt32(st); int ii = fpservice.AddFlatPLC(fpm); } } return(i.ToString()); }
public async Task EditFlat_NullViewModel_Warning() { var flatRepoMoq = new Mock <IFlatRepository>(); var controller = new FlatService(flatRepoMoq.Object); var response = await controller.EditFlat(null); Assert.Equal(ResponseStatuses.Warning, response.Status); }
public async Task EditFlat_EmptyIdentifier_Warning() { var flatRepoMoq = new Mock <IFlatRepository>(); var controller = new FlatService(flatRepoMoq.Object); var response = await controller.EditFlat(new ViewModels.FlatFullInformationViewModel { Id = 0 }); Assert.Equal(ResponseStatuses.Warning, response.Status); }
public async Task <ServiceResponse <bool> > EditFlat([FromBody] FlatFullInformationViewModel model) { try { return(await _flatService.EditFlat(model)); } catch (Exception e) { _logger.LogError(e, $"exception in EditFlat, called with {model}"); return(ServiceResponse <bool> .Exception("An error occured during edit-flat request")); } }
public async Task EditFlat_KitchenAreaMoreThanFull_Warning(int full, int kitchen) { var flatRepoMoq = new Mock <IFlatRepository>(); var controller = new FlatService(flatRepoMoq.Object); var response = await controller.EditFlat(new ViewModels.FlatFullInformationViewModel { Id = 0, FullArea = full, KitchenArea = kitchen }); Assert.Equal(ResponseStatuses.Warning, response.Status); }
public async Task EditFlat_NoFlatInRepository_Warning() { var flatRepoMoq = new Mock <IFlatRepository>(); flatRepoMoq .Setup(m => m.GetById(1)) .Returns(Task.FromResult <Flat>(null)); var controller = new FlatService(flatRepoMoq.Object); var response = await controller.EditFlat(new ViewModels.FlatFullInformationViewModel { Id = 1 }); Assert.Equal(ResponseStatuses.Warning, response.Status); }
public async Task EditFlat_ShouldReturnOkResult() { var flatRepoMoq = new Mock <IFlatRepository>(); flatRepoMoq .Setup(m => m.GetById(1)) .Returns(Task.FromResult(new Flat { })); var controller = new FlatService(flatRepoMoq.Object); var response = await controller.EditFlat(new ViewModels.FlatFullInformationViewModel { Id = 1, FullArea = 3, KitchenArea = 3, Floor = 2, Cost = 232424 }); Assert.Equal(ResponseStatuses.Ok, response.Status); }