public async Task <OutputResponse> Update(FacilityTypeDTO facilityType)
        {
            var facilityTypeToUpdate = await _context.FacilityTypes.FirstOrDefaultAsync(x => x.FacilityTypeId.Equals(facilityType.FacilityTypeId));

            if (facilityTypeToUpdate == null)
            {
                return(new OutputResponse
                {
                    IsErrorOccured = true,
                    Message = "Identification type specified does not exist, update cancelled"
                });
            }

            //update Identification Type details
            facilityTypeToUpdate.FacilityTypeName = facilityType.FacilityTypeName;
            facilityTypeToUpdate.RowAction        = "U";
            facilityTypeToUpdate.ModifiedBy       = facilityType.CreatedBy;
            facilityTypeToUpdate.DateModified     = DateTime.UtcNow.AddHours(2);

            await _context.SaveChangesAsync();

            return(new OutputResponse
            {
                IsErrorOccured = false,
                Message = MessageHelper.UpdateSuccess
            });
        }
        public async Task <OutputResponse> Add(FacilityTypeDTO facilityType)
        {
            var isFound = await _context.FacilityTypes.AnyAsync(x => x.FacilityTypeName.ToLower() == facilityType.FacilityTypeName.ToLower());

            if (isFound)
            {
                return(new OutputResponse
                {
                    IsErrorOccured = true,
                    Message = "Identification type description already exist, duplicates not allowed"
                });
            }

            var mappedFacilityType = new AutoMapperHelper <FacilityTypeDTO, FacilityTypes>().MapToObject(facilityType);

            mappedFacilityType.RowAction   = "I";
            mappedFacilityType.DateCreated = DateTime.UtcNow.AddHours(2);

            await _context.FacilityTypes.AddAsync(mappedFacilityType);

            await _context.SaveChangesAsync();

            return(new OutputResponse
            {
                IsErrorOccured = false,
                Message = MessageHelper.AddNewSuccess
            });
        }
예제 #3
0
        public void MapFromDomainEntity_NullContent_ReturnNull()
        {
            //Act
            var response = FacilityTypeDTO.MapFromDatabaseEntity(null);

            //Assert
            Assert.IsNull(response);
        }
예제 #4
0
        public async Task <IActionResult> Update([FromBody] FacilityTypeDTO facilityType)
        {
            var outputHandler = await _service.Update(facilityType);

            if (outputHandler.IsErrorOccured)
            {
                return(BadRequest(outputHandler.Message));
            }

            return(Ok(outputHandler.Message));
        }
예제 #5
0
        public static FacilityType MapFromDomainEntity(FacilityTypeDTO facilityType)
        {
            if (facilityType == null)
            {
                return(null);
            }

            return(new FacilityType()
            {
                Id = facilityType.Id,
                Value = facilityType.Value,
                Position = facilityType.Position
            });
        }
예제 #6
0
        public void MapFromDomainEntity_ValidEntity_ReturnDTOEntity()
        {
            //Arrange
            var facilityType = new FacilityTypeDTO()
            {
                Id       = Guid.NewGuid(),
                Value    = "Headquarters",
                Position = 0
            };
            var response = FacilityType.MapFromDomainEntity(facilityType);

            Assert.IsNotNull(response);
            Assert.AreEqual(facilityType.Id, response.Id);
            Assert.AreEqual(facilityType.Value, response.Value);
            Assert.AreEqual(facilityType.Position, response.Position);
        }
        private async Task <FacilityTypeDTO> GetFacilityType(int facilityTypeId)
        {
            string url          = $"{CoreApiUrl}FacilityTypes/GetById?facilityTypeId={facilityTypeId}";
            var    FacilityType = new FacilityTypeDTO();

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

            var response = await HttpRequestFactory.Get(accessToken, url);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                FacilityType = response.ContentAsType <FacilityTypeDTO>();
            }
            else
            {
                ModelState.AddModelError("", HttpResponseHandler.Process(response));
            }
            return(FacilityType);
        }
        public async Task <IActionResult> Edit([Bind] FacilityTypeDTO facilityType)
        {
            string url = $"{CoreApiUrl}FacilityTypes/Update";

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

            var response = await HttpRequestFactory.Put(accessToken, url, facilityType);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                AppContextHelper.SetToastMessage("Facility type has been successfully updated", MessageType.Success, 1, Response);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                AppContextHelper.SetToastMessage("Failed to update facility type", MessageType.Danger, 1, Response);
                ModelState.AddModelError("", HttpResponseHandler.Process(response));
            }
            return(View(facilityType));
        }
        public async Task <IActionResult> VerifyDelete(int facilityTypeId)
        {
            string url          = $"{CoreApiUrl}FacilityTypes/Delete?facilityTypeId={facilityTypeId}";
            var    FacilityType = new FacilityTypeDTO();

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

            var response = await HttpRequestFactory.Delete(accessToken, url);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                AppContextHelper.SetToastMessage("Facility type has been successfully deleted", MessageType.Success, 1, Response);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                AppContextHelper.SetToastMessage("Failed to delete identification Type", MessageType.Danger, 1, Response);
                ModelState.AddModelError("", HttpResponseHandler.Process(response));
            }
            return(View(await GetFacilityType(facilityTypeId)));
        }