public IHttpActionResult Update([FromBody] SOWTrackResultDTO sowTrackResult)
        {
            //string accessType = "";
            //ThrowIfUserHasNoRole(accessType);
            if (sowTrackResult == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (sowTrackResult.SOWTrackResult_PK == 0)
            {
                throw new KairosException("Put method is not allowed because the requested primary key is '0' (zero) .");
            }

            using (var sowTrackResultUpdateHandler = new SOWTrackResultUpdateHandler(Db, ActiveUser, new SOWTrackResultValidator(), new SOWTrackResultFactory(Db, ActiveUser), new SOWTrackResultQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = sowTrackResultUpdateHandler.Save(sowTrackResult, DateTime.Now);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message)));
                    }
                    return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message)));
                }
            }
        }
Ejemplo n.º 2
0
        private SOWTrackResultEntryModel GetCreateStateModel()
        {
            SOWTrackResultEntryFormData formData = new SOWTrackResultEntryFormData();
            List <Control>    formControls       = CreateFormControls(0);
            SOWTrackResultDTO sowTrackResultDTO  = new SOWTrackResultDTO();

            return(new SOWTrackResultEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = sowTrackResultDTO,
            });
        }
Ejemplo n.º 3
0
        private SOWTrackResultEntryModel GetUpdateStateModel(int sowTrackResultPK)
        {
            SOWTrackResultEntryFormData formData = new SOWTrackResultEntryFormData();
            List <Control>    formControls       = CreateFormControls(sowTrackResultPK);
            SOWTrackResultDTO sowTrackResultDTO  = sowTrackResultQuery.GetByPrimaryKey(sowTrackResultPK);

            if (sowTrackResultDTO == null)
            {
                throw new KairosException($"Record with primary key '{sowTrackResultDTO.SOWTrackResult_PK}' is not found.");
            }

            return(new SOWTrackResultEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = sowTrackResultDTO,
            });
        }
        public IHttpActionResult Create([FromBody] SOWTrackResultDTO sowTrackResult)
        {
            string accessType = "";

            ThrowIfUserHasNoRole(accessType);
            if (sowTrackResult == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (sowTrackResult.SOWTrackResult_PK != 0)
            {
                throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) .");
            }
            using (var sowTrackResultUpdateHandler = new SOWTrackResultUpdateHandler(Db, ActiveUser, new SOWTrackResultValidator(), new SOWTrackResultFactory(Db, ActiveUser), new SOWTrackResultQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = sowTrackResultUpdateHandler.Save(sowTrackResultDTO: sowTrackResult, dateStamp: DateTime.Now);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new
                        {
                            status = true
                        }));
                    }

                    return(Ok(new
                    {
                        status = false,
                        message = saveResult.Message,
                        data = saveResult.ValidationResult
                    }));
                }
            }
        }
Ejemplo n.º 5
0
        private void AddSOWTrackResultIfUserRoleIsDriver(MobileCheckInDTO checkInDTO, DateTime dateStamp)
        {
            var possibleDriverRoleNames = new List <string>()
            {
                "Driver",
                "DT",
                "Drive Tester (DT)"
            };

            var jabatans = Db.tblM_KategoriJabatan.Where(x => x.Title.Contains("DT") || x.Title.Contains("Drive") || x.KategoriJabatan_PK == 2);

            var sowAssign = new SOWAssignQuery(Db).GetByPrimaryKey(checkInDTO.SOWAssign_FK);

            if (sowAssign == null)
            {
                throw new NullReferenceException($"Failed to create sow track result while checkin, taskid or assignId '{checkInDTO.SOWAssign_FK}' doesn't exist.");
            }

            var user = Db.tblM_User.Find(sowAssign.User_FK);

            if (user == null)
            {
                throw new NullReferenceException($"Failed to create sow track result while checkin, user id '{sowAssign.User_FK}' doesn't exist.");
            }

            var roleGroups = new RoleGroupQuery(Db).GetByUserFk(sowAssign.User_FK);

            var userIsDriver =
                roleGroups.Where(x => possibleDriverRoleNames.Contains(x.Title)).Count() > 0 ||
                jabatans.Where(x => x.KategoriJabatan_PK == user.KategoriJabatan_FK).Count() > 0;

            if (userIsDriver)
            {
                if (string.IsNullOrEmpty(checkInDTO.TaskNetwork))
                {
                    throw new Kairos.KairosException($"Task network is required for driver checkin.");
                }

                if (sowAssign != null)
                {
                    var sowTrack = new SOWTrackQuery(Db).GetBySOWFKAndTechnologyTitle(sowAssign.SOW_FK, checkInDTO.TaskNetwork);

                    if (sowTrack != null)
                    {
                        SOWTrackResultDTO sowTrackResultDTO = new SOWTrackResultDTO()
                        {
                            CheckIn_FK  = checkInDTO.CheckIn_PK,
                            SOWTrack_FK = sowTrack.SOWTrack_PK,
                            Status_FK   = 1,
                        };

                        SOWTrackResultFactory sowTrackResultFactory = new SOWTrackResultFactory(Db, User);
                        tblT_SOWTrackResult   sowTrackResult        = sowTrackResultFactory.CreateFromDTO(sowTrackResultDTO, dateStamp);
                        Db.tblT_SOWTrackResult.Add(sowTrackResult);
                    }
                    else
                    {
                        throw new Kairos.KairosException($"Invalid task network '{checkInDTO.TaskNetwork}', it's not registered in sow register.");
                    }
                }
            }
        }