public ObjectResponse <CopyDTO> GetLastCopy() { try { CopyDTO copyDTO = null; var response = _unitOfWork.CopiesRepository.GetAll().OrderByDescending(x => x.copy_id).FirstOrDefault(); if (response != null) { copyDTO = new CopyDTO { Id = response.copy_id, Available = response.available, }; } return(new ObjectResponse <CopyDTO> { Success = true, Data = copyDTO }); } catch (Exception ex) { return(new ObjectResponse <CopyDTO> { Success = false, Error = ex.GetBaseException().Message, Info = DB_GET_ERROR }); } }
public CopyDTO toDTO() { CopyDTO dto = new CopyDTO() { Available = this.Available, CopyID = this.CopyID, GameID = this.GameID, GameTitle = this.Game.Title, GameYear = this.Game.Year.Year, GenreID = this.Game.GenreID, GenreName = this.Game.Genre.Name, PublisherID = this.Game.PublisherID, PublisherName = this.Game.Publisher.Name }; return(dto); }
public ObjectResponse <CopyDTO> GetCopy(Expression <Func <copy, bool> > func) { try { var response = _unitOfWork.CopiesRepository.GetFirstWhere(func); if (response != null) { return(new ObjectResponse <CopyDTO> { Success = true, Data = CopyDTO.Create(response) }); } return(new ObjectResponse <CopyDTO> { Success = false, Error = "Copy Is Not Available Now" }); } catch (Exception ex) { return(new ObjectResponse <CopyDTO> { Success = false, Error = ex.GetBaseException().Message, Info = DB_GET_ERROR }); } }
protected void copyIdValidation_ServerValidate(object source, ServerValidateEventArgs args) { // Validate field for "is integer", int value; Boolean ret = true; LiteralCopyId.Text = ""; if (!Int32.TryParse(boxCopyId.Text, out value)) { ret = false; LiteralCopyId.Text = writeDigitsLabel(); } // Validate field for "require", if (string.IsNullOrEmpty(boxCopyId.Text)) { ret = false; LiteralCopyId.Text = writeRequireLabel(); } // Check if record exist in database if above validations are met if (ret) { // Get the copy record int copyId = Convert.ToInt32(boxCopyId.Text); copyDTO = BCopy.getCopyByCopyId(copyId); // If record does not exist, ret is set to false if (copyDTO.CopyId <= 0) { LiteralCopyId.Text = writeDBLabel(); ret = false; } } // IsValid is set to ret and return args.IsValid = ret; }
public ObjectResponse <List <CopyDTO> > GetAll() { try { var response = _unitOfWork.CopiesRepository.GetAll().Include(t => t.movy).Include(y => y.rentals).ToList(); if (!response.Any()) { return(new ObjectResponse <List <CopyDTO> > { Success = false, Error = "No Copies In System" }); } return(new ObjectResponse <List <CopyDTO> > { Success = true, Data = response.Select(x => CopyDTO.Create(x))?.ToList() }); } catch (Exception ex) { return(new ObjectResponse <List <CopyDTO> > { Success = false, Error = ex.GetBaseException().Message, Info = DB_GET_ERROR }); } }