/// <summary> /// updates a floor by dto /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <AlpApiResponse> UpdateFloor(FloorDto dto) { var response = new AlpApiResponse(); try { _logger.LogDebug(new { action = nameof(UpdateFloor), dto = dto?.ToString() }.ToString()); dto.Validate(); var updatedEntity = await _context.Floor.FirstOrDefaultAsync(floor => floor.FloorId == dto.Id); updatedEntity.UpdateEntityByDto(dto); await _context.SaveChangesAsync(); } catch (Exception e) { _logger.LogError(new { exception = e, message = e.Message, innerException = e, innerExceptionMessage = e.InnerException?.Message }.ToString()); response.Message = e.Message; response.Success = false; } return(response); }
public async Task <IActionResult> Immobilize([Required] string id, [FromBody] FloorDto floor) { if (string.IsNullOrEmpty(id) || string.IsNullOrWhiteSpace(id) || (floor == null) || (floor?.Level < 0) ) { return(BadRequest(new { message = "Invalid request", requestId = id, request = floor })); } var existsDto = await service.GetByIdAsync(id); if (existsDto == null) { return(NotFound(new { message = "Hardware not found", request = id })); } if (existsDto.IsImmobilized) { return(BadRequest(new { message = "Hardware is already immobilized", requestId = id, foundDto = existsDto, request = floor })); } existsDto.ImmobilizerFloor = floor; await service.UpdateAsync(id, existsDto); return(NoContent()); }
// POST api/floors public async Task <HttpResponseMessage> Post([FromBody] FloorDto floor) { try { var floorsModelAlreadyExists = m_floorsRepo.Get(floor.Id) != null; if (floorsModelAlreadyExists) { // we already have a floor with this ID return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { ReasonPhrase = "Floor with this ID already exists." }); } var roomsOnFloor = m_roomsRepo.GetAll().Where(x => x.FloorId == floor.Id); await m_floorsRepo.Add(new Floor { Id = floor.Id, FloorPhotoUrl = floor.FloorPhotoUrl, DisplayName = floor.DisplayName, Rooms = roomsOnFloor.ToList() }); return(new HttpResponseMessage(HttpStatusCode.OK)); } catch (Exception ex) { return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { ReasonPhrase = $"Something went wrong when trying to add the floor. ({ex.Message})" }); } }
private void ValidateFloor(FloorDto floorDto, long adminId) { if (_floorService.CheckFloorRepeated(floorDto, adminId)) { throw new ValidationException(ErrorCodes.FloorNameRepeated); } }
public FloorDto Update(int id, [FromBody] FloorDto floorDto) { Floor floor = floorDtoToFloorMapping.Map(floorDto); Floor actualFloor = dbContext.Floors .Include(f => f.Office) .Include(f => f.Workstations) .Include(f => f.Image) .SingleOrDefault(f => f.Id == id); if (floorDto.ImageUrl != null && floorDto.ImageUrl != string.Empty) { if (actualFloor.Image != null) { dbContext.Remove(actualFloor.Image); } actualFloor.Image = FileHelper.GetFileFromBase64(floorDto.ImageUrl); } floorUpdater.Update(actualFloor, floor); dbContext.SaveChanges(); return(floorToFloorDtoMapping.Map(actualFloor)); }
// PUT api/floors/5 public async Task <HttpResponseMessage> Put(int id, [FromBody] FloorDto floor) { try { var floorToUpdate = m_floorsRepo.Get(floor.Id); if (floorToUpdate == null) { // we already have a floor with this ID return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { ReasonPhrase = "Floor with this ID doesn't exist." }); } //userToUpdate.Id = user.Id; floorToUpdate.DisplayName = floor.DisplayName; floorToUpdate.FloorPhotoUrl = floor.FloorPhotoUrl; await m_floorsRepo.Update(floorToUpdate); return(new HttpResponseMessage(HttpStatusCode.OK)); } catch (Exception ex) { return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { ReasonPhrase = $"Something went wrong when trying to add the floor. ({ex.Message})" }); } }
public void UpdateFloor(FloorDto floorDto, long adminId) { ValidateFloor(floorDto, adminId); var floor = _floorService.Find(floorDto.FloorId); floor.FloorName = floorDto.FloorName; _floorService.Update(floor); SaveChanges(); }
public void AddFloor(FloorDto floorDto, long adminId) { ValidateFloor(floorDto, adminId); var floor = Mapper.Map <Floor>(floorDto); floor.AdminId = adminId; _floorService.Insert(floor); SaveChanges(); }
public bool Use(string id, [FromBody] FloorDto floor) { var f = new Floor(); f.Number = floor.Number; f.Building = floor.Building; return(_itemService.Use(id, f)); }
public async Task <List <HardwareDto> > LoadByFloorAsync(FloorDto floorDto) { var floor = TransformToEntity <Floor, FloorDto>(floorDto); var collection = await Repository.LoadByFloorAsync(floor); var collectioDto = TransformToDto(collection); return(collectioDto); }
public int addFloor(FloorDto dto) { Floor f = new Floor(); f.number = dto.number; _unitOfWork.FloorRepository.Add(f); _unitOfWork.SaveChanges(); return(f.Id); }
public FloorDto getFloorById(int id) { FloorDto dto = new FloorDto(); var x = _unitOfWork.FloorRepository.FindById(id); dto.Id = x.Id; dto.number = x.number; return(dto); }
public List <FloorDto> GetAllFloor() { try { List <FloorDto> list = new List <FloorDto>(); using (UnitOfWork unitofWork = new UnitOfWork()) { List <floor> collection = unitofWork.GetRepository <floor>().Select(null, null).ToList(); foreach (var item in collection) { FloorDto fDto = new FloorDto(); fDto.FloorID = item.FloorID; fDto.Name = item.Name; fDto.Map = item.Map; fDto.Other = item.Other; if (item.BuildID != null) { fDto.BuildID = item.BuildID.Value; } else { fDto.BuildID = 0; } if (item.BlockID != null) { fDto.BlockID = item.BlockID.Value; } else { fDto.BlockID = 0; } if (item.BuildID != 0 && item.BuildID != null) { var fBuild = unitofWork.GetRepository <build>().GetById(a => a.BuildID == fDto.BuildID); fDto.BuildDto = new BuildDto(); fDto.BuildDto.BuildID = fBuild.BuildID; fDto.BuildDto.Name = fBuild.Name; } if (item.BlockID != 0 && item.BlockID != null) { fDto.BlockDto = new BlockDto(); var fBlock = unitofWork.GetRepository <block>().GetById(a => a.BlockID == fDto.BlockID); fDto.BlockDto.BlockID = fBlock.BlockID; fDto.BlockDto.Name = fBlock.Name; } list.Add(fDto); } return(list); } } catch (Exception ex) { return(new List <FloorDto>()); } }
public static void UpdateEntityByDto(this Floor entity, FloorDto dto) { if (dto == null || entity == null) { return; } entity.FloorName = dto.Name; entity.BuildingId = dto.BuildingId; entity.Locked = dto.Locked; }
public bool EditFloor(int id, FloorDto dto) { var d = _unitOfWork.FloorRepository.FindById(id); if (d == null) { return(false); } d.number = dto.number; _unitOfWork.FloorRepository.Update(d); _unitOfWork.SaveChanges(); return(true); }
public FloorDto Add([FromBody] FloorDto floorDto) { Floor floor = floorDtoToFloorMapping.Map(floorDto); Office office = dbContext.Offices .Include(o => o.Floors) .SingleOrDefault(o => o.Id == floorDto.OfficeId); office.Floors.Add(floor); dbContext.SaveChanges(); return(floorToFloorDtoMapping.Map(floor)); }
public Task <AlpApiResponse> UpdateFloor([FromBody] FloorDto floor) { var sessionToken = HttpContext.Request.Headers["sessiontoken"]; if (!_accountService.Authorize(sessionToken, new List <RoleType> { RoleType.Admin })) { return(Task.FromResult(new AlpApiResponse { Success = false, Message = "Nincs jogosultsága ehhez a művelethez!" })); } return(_floorService.UpdateFloor(floor)); }
public static FloorDto GetFloorDtoListElement(Floor floor) { var result = new FloorDto() { Id = floor.FloorId, Description = floor.Description, BuildingId = floor.BuildingId, Walls = GetWallsDtoListNotSorted(floor.Walls.ToList()), Rooms = GetRoomsDtoList(floor.Rooms.ToList()), FloorNumber = floor.FloorNumber }; return(result); }
public List <FloorDto> getAllFloors() { List <FloorDto> res = new List <FloorDto>(); FloorDto dto = new FloorDto(); foreach (var item in _unitOfWork.FloorRepository.GetAll()) { dto.Id = item.Id; dto.number = item.number; res.Add(dto); dto = new FloorDto(); } return(res); }
public static Floor DtoToEntity(this FloorDto dto) { if (dto == null) { return(null); } return(new Floor { FloorId = dto.Id, FloorName = dto.Name, Building = dto.Building?.DtoToEntity(), BuildingId = dto.BuildingId, Locked = dto.Locked }); }
public ActionResult Create(int SelectBtype, FloorDto model, HttpPostedFileBase mapFile) { if (mapFile != null) { if (mapFile.ContentLength > 0) { string _FileName = model.Name + "_" + Path.GetFileName(mapFile.FileName); string _path = Path.Combine(Server.MapPath("~/Maps/Floor"), _FileName); mapFile.SaveAs(_path); model.Map = _FileName; } } ResultHelper result = JsonConvert.DeserializeObject <ResultHelper>(floorService.AddFloor(model)); ViewBag.Message = Helper.GetResultMessage(result.Result, result.ResultDescription); GetAllBuilds(); GetAllBlocks(); return(View()); }
public FloorDto GetFloor(int floorID) { try { using (UnitOfWork unitofWork = new UnitOfWork()) { floor item = new floor(); item = unitofWork.GetRepository <floor>().GetById(x => x.FloorID == floorID); FloorDto floorDto = new FloorDto(); floorDto.FloorID = item.FloorID; floorDto.Map = item.Map; floorDto.Name = item.Name; floorDto.Other = item.Other; if (item.BuildID != null) { floorDto.BuildID = item.BuildID.Value; } else { floorDto.BuildID = 0; } if (item.BlockID != null) { floorDto.BlockID = item.BlockID.Value; } else { floorDto.BlockID = 0; } return(floorDto); } } catch (Exception) { return(null); } }
public ResultHelper AddFloor(FloorDto floorDto) { try { floor item = new floor(); item.FloorID = floorDto.FloorID; item.Map = floorDto.Map; item.Name = floorDto.Name; item.Other = floorDto.Other; if (floorDto.BlockID == 0) { item.BlockID = null; } else { item.BlockID = floorDto.BlockID; } if (floorDto.BuildID == 0) { item.BuildID = null; } else { item.BuildID = floorDto.BuildID; } using (UnitOfWork unitofWork = new UnitOfWork()) { unitofWork.GetRepository <floor>().Insert(item); unitofWork.saveChanges(); return(new ResultHelper(true, item.FloorID, ResultHelper.SuccessMessage)); } } catch (Exception ex) { return(new ResultHelper(false, floorDto.FloorID, ResultHelper.UnSuccessMessage)); } }
/// <summary> /// adds a new floor to the database /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <AlpApiResponse <FloorDto> > InsertNewFloor(FloorDto dto) { var response = new AlpApiResponse <FloorDto>(); try { _logger.LogDebug(new { action = nameof(InsertNewFloor), dto = dto?.ToString() }.ToString()); dto.Validate(); var entity = dto.DtoToEntity(); entity.Building = null; await _context.Floor.AddAsync(entity); await _context.SaveChangesAsync(); response.Value = entity.EntityToDto(); } catch (Exception e) { _logger.LogError(new { exception = e, message = e.Message, innerException = e, innerExceptionMessage = e.InnerException?.Message }.ToString()); response.Message = e.Message; response.Success = false; } return(response); }
public ActionResult EditFloor(int id, FloorDto dto) { var x = _IAuctionService.EditFloor(id, dto); return(RedirectToAction("AddFloor")); }
public ActionResult AddFloor(FloorDto dto) { _IAuctionService.addFloor(dto); return(RedirectToAction("AddFloor")); }
public int Post(FloorDto floorDto) { return(_floorRepository.Add(floorDto)); }
public void Update(FloorDto floorDto) { _floorRepository.Update(floorDto); }
public IHttpActionResult Put(FloorDto floorDto) { _service.Update(floorDto); return(Ok()); }
public IHttpActionResult Post([FromBody] FloorDto floorDto) { int createdId = _service.Post(floorDto); return(Ok()); //for now }