public tblT_CheckIn CreateFromDTO(MobileCheckInDTO checkInDTO, DateTime dateStamp)
        {
            if (checkInDTO == null)
            {
                throw new ArgumentNullException("CheckIn model is null.");
            }
            checkInDTO.Status_FK    = (int)RecordStatus.Active;
            checkInDTO.CreatedBy    = User.Username;
            checkInDTO.CreatedDate  = dateStamp;
            checkInDTO.UpdatedBy    = User.Username;
            checkInDTO.UpdatedDate  = dateStamp;
            checkInDTO.WaktuCheckIn = dateStamp;
            tblT_CheckIn checkIn = checkInDTO.ToObject <tblT_CheckIn>();

            checkIn.LongitudeCheckIn = checkInDTO.LongitudeCheckIn;
            checkIn.LatitudeCheckIn  = checkInDTO.LatitudeCheckIn;
            checkIn.MCCCheckIn       = checkInDTO.MCCCheckIn;
            checkIn.MNCCheckIn       = checkInDTO.MNCCheckIn;
            checkIn.LACCheckIn       = checkInDTO.LACCheckIn;
            checkIn.CellIDCheckIn    = checkInDTO.CellIDCheckIn;
            checkIn.WaktuCheckIn     = dateStamp;
            checkIn.SOWAssign_FK     = checkInDTO.SOWAssign_FK;

            if (!string.IsNullOrEmpty(checkInDTO.FileString))
            {
                var bytes = Convert.FromBase64String(checkInDTO.FileString);
                checkIn.File = bytes;
            }


            return(checkIn);
        }
Esempio n. 2
0
        public tblT_CheckIn AddCheckIn(MobileCheckInDTO checkInDTO, DateTime dateStamp)
        {
            if (checkInDTO == null)
            {
                throw new ArgumentNullException("CheckIn model is null.");
            }
            tblT_CheckIn checkIn = checkInFactory.CreateFromDTO(checkInDTO, dateStamp);

            checkIn = Db.tblT_CheckIn.Add(checkIn);

            return(checkIn);
        }
Esempio n. 3
0
        public SaveResult <CheckInEntryModel> Save(MobileCheckInDTO checkInDTO, DateTime dateStamp)
        {
            checkInDTO.WaktuCheckIn = dateStamp;

            var checkins = checkInQuery.GetQuery().Where(x => x.SOWAssign_FK == checkInDTO.SOWAssign_FK).ToList();

            var uncheckedOuts = checkins.Where(x => x.WaktuCheckOut == null);

            if (uncheckedOuts != null)
            {
                if (uncheckedOuts.Count() > 0)
                {
                    throw new Kairos.KairosException($"Task ID '{uncheckedOuts.FirstOrDefault().SOWAssign_FK}' is not checked out. Cannot checkin, until previous task checked out.");
                }
            }

            ModelValidationResult validationResult = checkInValidator.Validate(checkInDTO);
            bool success            = false;
            CheckInEntryModel model = null;

            if (validationResult.IsValid)
            {
                tblT_CheckIn checkIn = AddCheckIn(checkInDTO, dateStamp);
                Db.SaveChanges();
                checkInDTO.CheckIn_PK = checkIn.CheckIn_PK;
                AddSOWTrackResultIfUserRoleIsDriver(checkInDTO, dateStamp);
                Db.SaveChanges();
                success = true;
                model   = checkInEntryDataProvider.Get(checkIn.CheckIn_PK);
            }

            return(new SaveResult <CheckInEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
Esempio n. 4
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.");
                    }
                }
            }
        }