Пример #1
0
        public async Task <IActionResult> Post([FromBody] hwm entity)
        {
            try
            {
                if (!isValid(entity))
                {
                    return(new BadRequestResult());
                }

                if (string.IsNullOrEmpty(entity.hwm_label))
                {
                    entity.hwm_label = "no_label";
                }

                var loggedInMember = LoggedInUser();
                if (loggedInMember == null)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                entity.last_updated    = DateTime.Now;
                entity.last_updated_by = loggedInMember.member_id;

                //sm(agent.Messages);
                return(Ok(await agent.Add <hwm>(entity)));
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
Пример #2
0
        public async Task <IActionResult> ApproveHWM(int hwmId)
        {
            try
            {
                hwm      aHWM           = null;
                approval anEntity       = null;
                Int32    loggedInUserId = 0;

                if (hwmId <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }

                anEntity = new approval();
                aHWM     = await agent.Find <hwm>(hwmId);

                if (aHWM == null)
                {
                    return(new BadRequestObjectResult("Invalid hwm id"));
                }

                //get logged in user
                var loggedInMember = LoggedInUser();
                if (loggedInMember == null)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                loggedInUserId = loggedInMember.member_id;

                //set time and user of approval
                anEntity.approval_date = DateTime.UtcNow;
                anEntity.member_id     = loggedInMember.member_id;

                anEntity = await agent.Add <approval>(anEntity);

                //set HWM approvalID
                aHWM.approval_id = anEntity.approval_id;

                // last updated parts
                aHWM.last_updated    = DateTime.Now;
                aHWM.last_updated_by = loggedInUserId;
                await agent.Update <hwm>(aHWM.hwm_id, aHWM);

                //sm(agent.Messages);
                return(Ok(anEntity));
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
Пример #3
0
        public async Task <IActionResult> UnApproveHWM(int hwmId)
        {
            try
            {
                hwm aHWM = null;
                //Return BadRequest if missing required fields
                if (hwmId <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }

                //fetch the object to be updated (assuming that it exists)
                aHWM = await agent.Find <hwm>(hwmId);

                if (aHWM == null)
                {
                    return(new BadRequestObjectResult("invalid hwm id"));
                }

                Int32 apprId = aHWM.approval_id.HasValue ? aHWM.approval_id.Value : 0;

                //remove id from hwm
                aHWM.approval_id = null;

                // last updated parts
                var   loggedInMember = LoggedInUser();
                Int32 loggedInUserId = loggedInMember.member_id;
                aHWM.last_updated    = DateTime.Now;
                aHWM.last_updated_by = loggedInUserId;
                await agent.Update <hwm>(aHWM.hwm_id, aHWM);

                approval anApproval = await agent.Find <approval>(apprId);

                //remove approval
                await agent.Delete <approval>(anApproval);

                //sm(agent.Messages);

                return(Ok());
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
Пример #4
0
        public async Task Post()
        {
            //Arrange
            var entity = new hwm()
            {
                site_id = 55, event_id = 1, hwm_type_id = 11, hwm_quality_id = 3, latitude_dd = 45, longitude_dd = -88, hcollect_method_id = 2, hwm_environment = "blah", flag_date = DateTime.Now, hdatum_id = 1, flag_member_id = 22
            };


            //Act
            var response = await controller.Post(entity);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(response);
            var result   = Assert.IsType <hwm>(okResult.Value);


            Assert.Equal(55, result.site_id);
        }
Пример #5
0
        public async Task <IActionResult> Put(int id, [FromBody] hwm entity)
        {
            try
            {
                if (id < 0 || !isValid(entity))
                {
                    return(new BadRequestResult());
                }

                var loggedInMember = LoggedInUser();
                if (loggedInMember == null)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                entity.last_updated    = DateTime.Now;
                entity.last_updated_by = loggedInMember.member_id;

                return(Ok(await agent.Update <hwm>(id, entity)));
            }
            catch (Exception ex)
            {
                return(await HandleExceptionAsync(ex));
            }
        }