public IActionResult RequestForm(EquipmentRequest equipmentRequest)
        {
            Debug.WriteLine("Checking");
            Debug.WriteLine(equipmentRequest.EqType);
            if (ModelState.IsValid)
            {
                // Store requests from users
                Debug.WriteLine("Request Being Added");
                Repository.AddRequest(equipmentRequest);
                return(View("Confirmation", equipmentRequest));
            }
            else
            {
                var x = new EquipmentRequest();
                x.Types = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Laptop", Value = "Laptop"
                    },
                    new SelectListItem {
                        Text = "Tablet", Value = "Tablet"
                    },
                    new SelectListItem {
                        Text = "Phone", Value = "Phone"
                    },
                    new SelectListItem {
                        Text = "Other", Value = "Other"
                    }
                };

                return(View(x));
            }
        }
        public async Task <ActionResult <EquipmentRequestDto> > GetEquipmentRequest(Guid id)
        {
            EquipmentRequest request = await _logic.GetEquipmentRequestById(id);

            EquipmentRequestDto convertedRequest = _mapper.ConvertEquipmentRequestToEquipmentRequestDto(request);

            var token = await HttpContext.GetTokenAsync("access_token");

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var response = await httpClient.GetAsync($"api/Team/{request.TeamID}");

                string apiResponse = await response.Content.ReadAsStringAsync();

                var team = JsonConvert.DeserializeObject <TeamDto>(apiResponse);
                convertedRequest.Team = team;

                response = await httpClient.GetAsync($"api/User/{request.UserID}");

                apiResponse = await response.Content.ReadAsStringAsync();

                var user = JsonConvert.DeserializeObject <UserDto>(apiResponse);
                convertedRequest.User = user;

                EquipmentItem item = await _logic.GetEquipmentItemById(request.ItemId);

                convertedRequest.Item = item;
            }

            return(convertedRequest);
        }
Ejemplo n.º 3
0
        public async void TestForGetEquipmentRequestById()
        {
            var options = new DbContextOptionsBuilder <EquipmentContext>()
                          .UseInMemoryDatabase(databaseName: "p3GetRequestById")
                          .Options;

            using (var context = new EquipmentContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo r       = new Repo(context, new NullLogger <Repo>());
                var  request = new EquipmentRequest
                {
                    RequestID   = Guid.NewGuid(),
                    TeamID      = Guid.NewGuid(),
                    UserID      = "fred",
                    RequestDate = DateTime.Now,
                    Message     = "i need equipment now!",
                    ItemId      = 53,
                    Status      = "Approved"
                };
                r.EquipmentRequests.Add(request);
                await r.CommitSave();

                var getRequest = await r.GetEquipmentRequestById(request.RequestID);

                Assert.Equal("fred", getRequest.UserID);
                Assert.Equal("i need equipment now!", getRequest.Message);
                Assert.Equal(53, getRequest.ItemId);
                Assert.Equal("Approved", getRequest.Status);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Edit an EquipmentRequest
        /// </summary>
        /// <param name="id">EqupmentRequestID</param>
        /// <param name="editEquipmentRequestDto">new information from input</param>
        /// <returns>modified EquipmentRequest</returns>
        public async Task <EquipmentRequest> EditEquipmentRequest(Guid id, EditEquipmentRequestDto editEquipmentRequestDto)
        {
            EquipmentRequest editedEquipmentRequest = await GetEquipmentRequestById(id);

            if (editedEquipmentRequest != null && editedEquipmentRequest.Status != editEquipmentRequestDto.Status)
            {
                editedEquipmentRequest.Status = editEquipmentRequestDto.Status;
            }
            await _repo.CommitSave();

            return(editedEquipmentRequest);
        }
Ejemplo n.º 5
0
        public async void TestForGetEquipmentRequests()
        {
            var options = new DbContextOptionsBuilder <EquipmentContext>()
                          .UseInMemoryDatabase(databaseName: "p3ControllerGetEquipmentRequests")
                          .Options;

            using (var context = new EquipmentContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo   r = new Repo(context, new NullLogger <Repo>());
                Logic  l = new Logic(r, new NullLogger <Repo>());
                Mapper m = new Mapper();
                EquipmentController controller = new EquipmentController(l, m);
                var request = new EquipmentRequest
                {
                    RequestID   = Guid.NewGuid(),
                    TeamID      = Guid.NewGuid(),
                    UserID      = "fred",
                    RequestDate = DateTime.Now,
                    Message     = "i need equipment now!",
                    ItemId      = 53,
                    Status      = "Approved"
                };
                r.EquipmentRequests.Add(request);
                var request2 = new EquipmentRequest
                {
                    RequestID   = Guid.NewGuid(),
                    TeamID      = Guid.NewGuid(),
                    UserID      = "tom",
                    RequestDate = DateTime.Now,
                    Message     = "broken helmet",
                    ItemId      = 27,
                    Status      = "Pending"
                };
                r.EquipmentRequests.Add(request2);
                await r.CommitSave();

                //var getRequests = await controller.GetEquipmentRequests();
                //var convertedList = (List<EquipmentRequest>)getRequests;

                //Assert.Equal("fred", convertedList[0].UserID);
                //Assert.Equal("i need equipment now!", convertedList[0].Message);
                //Assert.Equal(53, convertedList[0].ItemId);
                //Assert.Equal("Approved", convertedList[0].Status);
                //Assert.Equal("tom", convertedList[1].UserID);
                //Assert.Equal("broken helmet", convertedList[1].Message);
                //Assert.Equal(27, convertedList[1].ItemId);
                //Assert.Equal("Pending", convertedList[1].Status);
            }
        }
Ejemplo n.º 6
0
        public EquipmentRequestDto ConvertEquipmentRequestToEquipmentRequestDto(EquipmentRequest equipment)
        {
            EquipmentRequestDto convertedRequest = new EquipmentRequestDto()
            {
                RequestID   = equipment.RequestID,
                UserID      = equipment.UserID,
                TeamID      = equipment.TeamID,
                RequestDate = equipment.RequestDate,
                Message     = equipment.Message,
                ItemId      = equipment.ItemId,
                Status      = equipment.Status
            };

            return(convertedRequest);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create new EquipmentRequest
        /// </summary>
        /// <param name="createEquipmentRequestDto">EquipmentRequest from input</param>
        /// <returns>EquipmentRequest</returns>
        public async Task <EquipmentRequest> CreateEquipmentRequest(CreateEquipmentRequestDto createEquipmentRequestDto)
        {
            EquipmentRequest newEquipmentRequest = new EquipmentRequest()
            {
                UserID      = createEquipmentRequestDto.UserID,
                TeamID      = createEquipmentRequestDto.TeamID,
                RequestDate = DateTime.Now,
                Message     = createEquipmentRequestDto.Message,
                ItemId      = createEquipmentRequestDto.ItemID,
                Status      = createEquipmentRequestDto.Status
            };
            await _repo.EquipmentRequests.AddAsync(newEquipmentRequest);

            await _repo.CommitSave();

            return(newEquipmentRequest);
        }
        public void ValidateEquipmentRequest()
        {
            var request = new EquipmentRequest
            {
                RequestID   = Guid.NewGuid(),
                TeamID      = Guid.NewGuid(),
                UserID      = "fred",
                RequestDate = DateTime.Now,
                Message     = "i need equipment now!",
                ItemId      = 53,
                Status      = "Approved"
            };

            var results = ValidateModel(request);

            Assert.True(results.Count == 0);
        }
Ejemplo n.º 9
0
        public async void TestForEditEquipmentRequest()
        {
            var options = new DbContextOptionsBuilder <EquipmentContext>()
                          .UseInMemoryDatabase(databaseName: "p3ControllerEditRequest")
                          .Options;

            using (var context = new EquipmentContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo   r = new Repo(context, new NullLogger <Repo>());
                Logic  l = new Logic(r, new NullLogger <Repo>());
                Mapper m = new Mapper();
                EquipmentController controller = new EquipmentController(l, m);
                var request = new EquipmentRequest
                {
                    RequestID   = Guid.NewGuid(),
                    TeamID      = Guid.NewGuid(),
                    UserID      = "fred",
                    RequestDate = DateTime.Now,
                    Message     = "i need equipment now!",
                    ItemId      = 53,
                    Status      = "Approved"
                };
                r.EquipmentRequests.Add(request);
                await r.CommitSave();

                var editRequestDto = new EditEquipmentRequestDto
                {
                    Status = "Pending"
                };

                var editRequest = await controller.EditEquipmentRequest(request.RequestID, editRequestDto);

                Assert.Equal("fred", editRequest.Value.UserID);
                Assert.Equal("i need equipment now!", editRequest.Value.Message);
                Assert.Equal(53, editRequest.Value.ItemId);
                Assert.Equal("Pending", editRequest.Value.Status);
            }
        }
        public IActionResult RequestForm()
        {
            var x = new EquipmentRequest();

            x.Types = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Laptop", Value = "Laptop"
                },
                new SelectListItem {
                    Text = "Tablet", Value = "Tablet"
                },
                new SelectListItem {
                    Text = "Phone", Value = "Phone"
                },
                new SelectListItem {
                    Text = "Other", Value = "Other"
                }
            };

            return(View(x));
        }
Ejemplo n.º 11
0
        public Task <IReadOnlyCollection <Equipment> > GetByRequestAsync(EquipmentRequest request, CancellationToken cancellation)
        {
            return(_equipmentRepository.QueryCollectionAsync(q =>
            {
                var query = q;

                if (request.Node.HasValue)
                {
                    query = query.Where(e => e.IsNode == request.Node.Value);
                }

                query = request.ParentIds.IsNotEmpty()
                    ? query.Where(e => e.ParentId != null && request.ParentIds.Contains(e.ParentId.Value))
                    : query.Where(e => e.ParentId == null);

                if (!string.IsNullOrEmpty(request.Name))
                {
                    query = query.Where(e => e.Name.StartsWith(request.Name));
                }

                return query;
            }, cancellation));
        }
 /// <summary>
 /// Инцииализирует экземпляр <see cref="GetEquipmentByRequestQuery"/>.
 /// </summary>
 /// <param name="request">Запрос на получение оборудования.</param>
 public GetEquipmentByRequestQuery(EquipmentRequest request)
 {
     Request = request;
 }
Ejemplo n.º 13
0
 public async Task <IActionResult> GetByRequestAsync(EquipmentRequest request, CancellationToken cancellation)
 {
     return(Ok(await _mediatr.Send(new GetEquipmentByRequestQuery(request), cancellation)));
 }
        public async Task <EquipmentResponse> UpdateEquipmentByGuid(string guid, EquipmentRequest values)
        {
            EquipmentResponse _response = new EquipmentResponse();

            try
            {
                EquipmentEntity equipment = await _context.Equipment.Where(x => x.EquipmentGuid == guid && x.IsDeleted == false).FirstOrDefaultAsync();

                if (equipment == null)
                {
                    _response.Code         = "E001";
                    _response.Message      = _localizer["norecords"];
                    _response.DataCount    = 0;
                    _response.ResponseDate = DateTime.Now.ToUniversalTime();
                    _response.Results      = null;
                }
                else
                {
                    if (!string.IsNullOrEmpty(values.Name))
                    {
                        equipment.Name = values.Name;
                    }
                    if (values.Quantity > 1)
                    {
                        equipment.Quantity = values.Quantity;
                    }
                    if (values.UnitPrice > 0.01m)
                    {
                        equipment.UnitPrice = values.UnitPrice;
                    }
                    if (values.RateOfUse >= 0.0m && values.RateOfUse <= 100.0m)
                    {
                        equipment.RateOfUse = values.RateOfUse;
                    }
                    if (values.DateofSupply != null)
                    {
                        equipment.DateofSupply = values.DateofSupply;
                    }

                    if (equipment.Validate(validationContext: null).Count() == 0)
                    {
                        await _context.SaveChangesAsync();

                        _response.Code         = "E000";
                        _response.Message      = _localizer["success"];
                        _response.DataCount    = 1;
                        _response.ResponseDate = DateTime.Now.ToUniversalTime();
                        _response.Results.Add(equipment);
                    }
                    else
                    {
                        _response.Code    = "E001";
                        _response.Message = _localizer["check_values"];
                        foreach (System.ComponentModel.DataAnnotations.ValidationResult item in equipment.Validate(validationContext: null).ToList())
                        {
                            _response.Message += item.ErrorMessage + " ";
                        }
                        _response.DataCount    = 0;
                        _response.ResponseDate = DateTime.Now.ToUniversalTime();
                        _response.Results      = null;
                    }
                }
            }
            catch (Exception ex)
            {
                _response.Code         = "E999";
                _response.Message      = ex.Message;
                _response.ResponseDate = DateTime.Now.ToUniversalTime();
                _response.Results      = null;
            }

            return(_response);
        }
Ejemplo n.º 15
0
 public async Task <EquipmentResponse> Update([FromQuery] string guid, [FromBody] EquipmentRequest values)
 {
     return(await _equipment.UpdateEquipmentByGuid(guid, values));
 }