public List <string> SendWorkHours(WorkHourJson workHourJson)//JObject jsonObject
        {
            UnitOfWork       uow         = new UnitOfWork();
            UserManager      userManager = new UserManager(uow);
            TimeSheetManager WHM         = new TimeSheetManager(uow);
            User             currUser    = new UserHelper().GetCurrent();
            Validations      validate    = new Validations();
            var           WorkHours      = WHM.GetBydateAndUserId(workHourJson.Date, currUser.ID);
            List <string> result         = new List <string>();

            foreach (var wh in WorkHours.ToList())
            {
                if (wh.WorkflowStage.IsFirst)
                {
                    result = validate.ValidateRegisterWorkHour(wh);
                    if (result.Count() > 0)
                    {
                        return(result);
                    }

                    WHM.SendWorkHour(wh);
                    HistoryUtilities.RegisterSendHistory(wh);
                    result.Add("عملیات ارسال کارکرد ها با موفقیت انجام گردید");
                }
            }

            return(result);
        }
        public List <string> SaveWorkHours(WorkHourJson workHourJson)
        {
            List <string> result = new List <string>();

            try
            {
                UnitOfWork       uow         = new UnitOfWork();
                UserManager      userManager = new UserManager(uow);
                TaskManager      taskManager = new TaskManager(uow);
                ProjectManager   prjManager  = new ProjectManager(uow);
                TimeSheetManager tsManager   = new TimeSheetManager(uow);
                Validations      validate    = new Validations();
                User             currUser    = new UserHelper().GetCurrent();
                WorkHour         workHour    = workHourJson.ToWorkHour();
                workHour.Task            = taskManager.GetByID(workHour.TaskID);
                workHour.TaskID          = workHour.Task.ID;
                workHour.Project         = prjManager.GetByID(workHourJson.ProjectID);
                workHour.ProjectId       = workHour.Project.ID;
                workHour.EmployeeID      = currUser.ID;
                workHour.Employee        = userManager.GetByID(currUser.ID);
                workHour.WorkflowStage   = new WorkflowManager(uow).FirstStage();
                workHour.WorkflowStageID = workHour.WorkflowStage.ID;
                workHour.Description     = workHourJson.Description;
                tsManager.SaveWorkHour(workHour);
                HistoryUtilities.RegisterSaveHistory(workHour);
            }

            catch (ValidationException ex)
            {
                result = ex.Errors;
            }
            return(result);
        }
        public bool DeleteWorkHours(WorkHourJson workHourJson)//JObject jsonObject)
        {
            UnitOfWork       uow = new UnitOfWork();
            TimeSheetManager WHM = new TimeSheetManager(uow);

            WHM.DeleteWorkHour(workHourJson.ID);
            return(true);
        }
        public IEnumerable <WorkHourJson> GetConfirmedWorkHours(WorkHourJson workHourJson)//JObject jsonObject)
        {
            UnitOfWork       uow      = new UnitOfWork();
            TimeSheetManager WHM      = new TimeSheetManager(uow);
            User             currUser = new UserHelper().GetCurrent();

            return(new WorkHourAssembler().ToJsons(WHM.GetConfirmedWorkHours(workHourJson.Date, currUser.ID)));
        }
        public PresenceHour GetPresenceHourByDate(WorkHourJson workHourJson)//JObject jsonObject)
        {
            UnitOfWork       uow      = new UnitOfWork();
            TimeSheetManager WHM      = new TimeSheetManager(uow);
            User             currUser = new UserHelper().GetCurrent();

            return(WHM.GetPresenceHourByUserIdAndDate(currUser.ID, workHourJson.Date));
        }
        public static WorkHourJson ToJson(this WorkHour entity)
        {
            var result = new WorkHourJson();

            result.ID     = entity.ID;
            result.Date   = entity.Date;
            result.TaskID = entity.Task.ID;
            result.Hours  = entity.Hours;

            return(result);
        }
        public IEnumerable <WorkHourJson> GetWorkHoursByDate(WorkHourJson WorkHourJson)
        {
            var              result           = new List <WorkHourJson>();
            UnitOfWork       uow              = new UnitOfWork();
            UserManager      userManager      = new UserManager(uow);
            TimeSheetManager timeSheetManager = new TimeSheetManager(uow);
            User             currUser         = new UserHelper().GetCurrent();

            result = new WorkHourAssembler().ToJsons(timeSheetManager.GetWorkHoursByUser(currUser, WorkHourJson.Date, WorkHourJson.Date)).ToList();
            return(result);
        }
        public IEnumerable <WorkHourHistoryJson> GetHistoryWorkHour(WorkHourJson WorkHourJson)
        {
            var                    result          = new List <WorkHourHistoryJson>();
            UnitOfWork             uow             = new UnitOfWork();
            UserManager            userManager     = new UserManager(uow);
            WorkHourHistoryManager historyManagerh = new WorkHourHistoryManager(uow);
            User                   currUser        = new UserHelper().GetCurrent();

            result = new WorkHourHistoryAssembler().ToJsons(historyManagerh.GetByWorkHourID(WorkHourJson.ID)).ToList();
            return(result);
        }
        public IEnumerable <TimeSheetJson> GetPreviousPeriod(WorkHourJson workHourJson)
        {
            List <TimeSheetJson> result = new List <TimeSheetJson>();

            if (workHourJson == null)
            {
                workHourJson      = new WorkHourJson();
                workHourJson.Date = DateTime.Now;
            }
            var                  startDate           = workHourJson.Date;
            UnitOfWork           uow                 = new UnitOfWork();
            UserManager          userManager         = new UserManager(uow);
            ProjectManager       projectManager      = new Domain.ProjectManager(uow);
            TimeSheetManager     timeSheetManager    = new TimeSheetManager(uow);
            DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow);
            //SyncWithPWA(uow);
            User          currUser      = new UserHelper().GetCurrent();
            DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser);

            var dt = startDate.AddDays(-1);

            DateTime fromDate = dt.AddDays(-displayPeriod.NumOfDays);
            DateTime toDate   = dt;

            if (displayPeriod.IsWeekly)
            {
                fromDate = dt.StartOfWeek(DayOfWeek.Saturday);
                toDate   = dt.EndOfWeek(DayOfWeek.Friday);

                IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
                result = TimeSheetAssembler.ToJsonsForRegister(presHours, workHours);
            }
            else
            {
                IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                IEnumerable <WorkHour>     workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate);
                if (presHours.Count() < displayPeriod.NumOfDays)
                {
                    fromDate  = timeSheetManager.GetFirstPresenceHour().Date;
                    toDate    = fromDate.AddDays(displayPeriod.NumOfDays);
                    presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate);
                }
                result = TimeSheetAssembler.ToJsonsForRegister(presHours, workHours);
            }



            return(result);
        }
Ejemplo n.º 10
0
        public WorkHourJson ToJson(WorkHour entity)
        {
            var result = new WorkHourJson();

            result.ID                 = entity.ID;
            result.Action             = entity.Action;
            result.PersianDate        = DateUtility.GetPersianDate(entity.Date);
            result.Description        = entity.Description;
            result.UserName           = entity.Employee.UserName;
            result.Hours              = entity.Hours;
            result.ProjectTitle       = entity.Project.Title;
            result.TaskTitle          = entity.Task.Title;
            result.WorkFlowStageTitle = entity.WorkflowStage.Title;
            return(result);
        }
        public static WorkHour ToWorkHour(this WorkHourJson jsonObject)
        {
            WorkHour result = new WorkHour();

            result.ID              = Guid.NewGuid();
            result.Date            = jsonObject.Date;
            result.EmployeeID      = jsonObject.EmployeeID;
            result.TaskID          = jsonObject.TaskID;
            result.ProjectId       = jsonObject.ProjectID;
            result.Hours           = Math.Round(TimeSpan.Parse(jsonObject.Hours.ToString()).TotalHours, 2);
            result.WorkflowStageID = jsonObject.WorkflowStageID;



            return(result);
        }
Ejemplo n.º 12
0
        public static WorkHour ToWorkHour(this WorkHourJson jsonObject)
        {
            WorkHour result = new WorkHour();

            if (!jsonObject.EmployeeID.HasValue)
            {
                jsonObject.EmployeeID = Guid.Empty;
            }

            result.ID              = jsonObject.ID.HasValue ? jsonObject.ID.Value : Guid.NewGuid();
            result.Date            = jsonObject.Date;
            result.EmployeeID      = jsonObject.EmployeeID.Value;
            result.TaskID          = jsonObject.TaskID;
            result.ProjectId       = jsonObject.ProjectID;
            result.Minutes         = jsonObject.Minutes;
            result.WorkflowStageID = jsonObject.WorkflowStageID;



            return(result);
        }
        public List <string> SendWorkHour(WorkHourJson workHourJson)//JObject jsonObject
        {
            UnitOfWork       uow         = new UnitOfWork();
            UserManager      userManager = new UserManager(uow);
            TimeSheetManager WHM         = new TimeSheetManager(uow);
            User             currUser    = new UserHelper().GetCurrent();
            Validations      validate    = new Validations();
            var           WorkHour       = WHM.GetByID(workHourJson.ID);
            List <string> result         = new List <string>();

            result = validate.ValidateRegisterWorkHour(WorkHour);

            if (result.Count() == 0)
            {
                if (WorkHour.WorkflowStage.IsFirst)
                {
                    WHM.SendWorkHour(WorkHour);
                    HistoryUtilities.RegisterSendHistory(WorkHour);
                    result.Add("ارسال کارکرد با موفقیت انجام گردید");
                }
            }

            return(result);
        }