Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind] TeamMappingResponse teamMappingResponse)
        {
            ResponseTeamMappingDTO responseTeamMember = new ResponseTeamMappingDTO
            {
                CreatedBy    = teamMappingResponse.CreatedBy,
                DistrictCode = teamMappingResponse.DistrictCode,
                MappingId    = teamMappingResponse.MappingId,
                TeamMemberId = teamMappingResponse.TeamMemberId
            };

            string url = $"{CoreApiUrl}ResponseTeamMappings/Add";

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

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

            if (response.StatusCode == HttpStatusCode.Created)
            {
                AppContextHelper.SetToastMessage("Response team member has been successfully mapped", MessageType.Success, 1, Response);
                return(RedirectToAction(nameof(Index), new { teamMemberId = _teamMemberId, teamMemberName = _teamMemberName }));
            }
            else
            {
                AppContextHelper.SetToastMessage("Failed to map response team member", MessageType.Danger, 1, Response);
                ModelState.AddModelError("", HttpResponseHandler.Process(response));
            }
            ViewBag.TeamMemberName = _teamMemberName;
            return(View(teamMappingResponse));
        }
Ejemplo n.º 2
0
        public async Task <OutputResponse> Add(ResponseTeamMappingDTO teamMapping)
        {
            var isFound = await _context.ResponseTeamMappings.AnyAsync(x => x.TeamMemberId == teamMapping.TeamMemberId &&
                                                                       x.DistrictCode == teamMapping.DistrictCode);

            if (isFound)
            {
                return(new OutputResponse
                {
                    IsErrorOccured = true,
                    Message = "Team member with this district already exist, duplicates not allowed"
                });
            }

            var mappedTeamMapping = new AutoMapperHelper <ResponseTeamMappingDTO, ResponseTeamMappings>().MapToObject(teamMapping);

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

            await _context.ResponseTeamMappings.AddAsync(mappedTeamMapping);

            await _context.SaveChangesAsync();

            return(new OutputResponse
            {
                IsErrorOccured = false,
                Message = MessageHelper.AddNewSuccess
            });
        }
Ejemplo n.º 3
0
        public async Task <OutputResponse> Update(ResponseTeamMappingDTO teamMapping)
        {
            var teamMappingToUpdate = await _context.ResponseTeamMappings.FirstOrDefaultAsync(x => x.MappingId.Equals(teamMapping.MappingId));

            if (teamMappingToUpdate == null)
            {
                return(new OutputResponse
                {
                    IsErrorOccured = true,
                    Message = "Team member mapping specified does not exist, update cancelled"
                });
            }

            //update details
            teamMappingToUpdate.TeamMemberId = teamMapping.TeamMemberId;
            teamMappingToUpdate.DistrictCode = teamMapping.DistrictCode;
            teamMappingToUpdate.RowAction    = "U";
            teamMappingToUpdate.ModifiedBy   = teamMapping.CreatedBy;
            teamMappingToUpdate.DateModified = DateTime.UtcNow.AddHours(2);

            await _context.SaveChangesAsync();

            return(new OutputResponse
            {
                IsErrorOccured = false,
                Message = MessageHelper.UpdateSuccess
            });
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Update([FromBody] ResponseTeamMappingDTO mapping)
        {
            var outputHandler = await _service.Update(mapping);

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

            return(Ok(outputHandler.Message));
        }