public async Task <OutputResponse> Update(ResourceAllocationDTO resource)
        {
            var resourceToUpdate = await _context.ResourcesAllocation.FirstOrDefaultAsync(x => x.ResourceAllocationId.Equals(resource.ResourceAllocationId));

            if (resourceToUpdate == null)
            {
                return(new OutputResponse
                {
                    IsErrorOccured = true,
                    Message = "Resource allocation specified does not exist, update cancelled"
                });
            }

            //update details
            resourceToUpdate.PatientStatusId  = resource.PatientStatusId;
            resourceToUpdate.RequiredQuantity = resource.RequiredQuantity;
            resourceToUpdate.ResourceId       = resource.ResourceId;
            resourceToUpdate.RowAction        = "U";
            resourceToUpdate.ModifiedBy       = resource.CreatedBy;
            resourceToUpdate.DateModified     = DateTime.UtcNow.AddHours(2);

            await _context.SaveChangesAsync();

            return(new OutputResponse
            {
                IsErrorOccured = false,
                Message = MessageHelper.UpdateSuccess
            });
        }
        public async Task <IActionResult> Update([FromBody] ResourceAllocationDTO resourceAllocation)
        {
            var outputHandler = await _service.Update(resourceAllocation);

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

            return(Ok(outputHandler.Message));
        }
        public async Task <OutputResponse> Add(ResourceAllocationDTO resource)
        {
            var mappedResourceAllocation = new AutoMapperHelper <ResourceAllocationDTO, ResourcesAllocation>().MapToObject(resource);

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

            await _context.ResourcesAllocation.AddAsync(mappedResourceAllocation);

            await _context.SaveChangesAsync();

            return(new OutputResponse
            {
                IsErrorOccured = false,
                Message = MessageHelper.AddNewSuccess
            });
        }
示例#4
0
        public async Task <IActionResult> VerifyDelete(string resourceAllocationId)
        {
            string url = $"{ResourcesApiUrl}ResourcesAllocation/Delete?resourceAllocationId={resourceAllocationId}";
            var    ResourcesAllocation = new ResourceAllocationDTO();

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

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

            if (response.StatusCode == HttpStatusCode.OK)
            {
                AppContextHelper.SetToastMessage("ResourcesAllocation has been successfully deleted", MessageType.Success, 1, Response);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                AppContextHelper.SetToastMessage("Failed to delete resourceAllocation", MessageType.Danger, 1, Response);
                ModelState.AddModelError("", HttpResponseHandler.Process(response));
            }
            return(View(await GetResourceAllocation(resourceAllocationId)));
        }
示例#5
0
        public async Task <IActionResult> Edit([Bind] ResourceAllocationResponseViewModel resourceAllocationResponseView)
        {
            ResourceAllocationDTO resourceAllocation = resourceAllocationResponseView.ResourceAllocationResponse;
            string url = $"{ResourcesApiUrl}ResourcesAllocation/Update";

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

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

            if (response.StatusCode == HttpStatusCode.OK)
            {
                AppContextHelper.SetToastMessage("ResourcesAllocation has been successfully updated", MessageType.Success, 1, Response);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                AppContextHelper.SetToastMessage("Failed to update resourceAllocation", MessageType.Danger, 1, Response);
                ModelState.AddModelError("", HttpResponseHandler.Process(response));
            }
            resourceAllocationResponseView.Resources = await GetResources();

            return(View(resourceAllocationResponseView));
        }