Esempio n. 1
0
        public TimeSpend ChangePaymentStatus(TimeSpend timeSpend, PaymentStatus newStatus)
        {
            if (!ProjectSecurity.CanEditPaymentStatus(timeSpend))
            {
                throw new SecurityException("Access denied.");
            }

            if (timeSpend == null)
            {
                throw new ArgumentNullException("timeSpend");
            }

            var task = taskDao.GetById(timeSpend.Task.ID);

            if (task == null)
            {
                throw new Exception("Task can't be null.");
            }

            ProjectSecurity.DemandEdit(timeSpend);

            if (timeSpend.PaymentStatus == newStatus)
            {
                return(timeSpend);
            }

            timeSpend.PaymentStatus = newStatus;

            return(timeSpendDao.Save(timeSpend));
        }
        private void SaveTimeSpends(ITimeEntry[] timeEntries)
        {
            TimeTrackingEngine timeTrackingEngine = _engineFactory.GetTimeTrackingEngine();

            foreach (var timeEntry in timeEntries)
            {
                try
                {
                    TimeSpend newTimeSpend = new TimeSpend()
                    {
                        Hours = (float)timeEntry.Hours,
                        Date  = timeEntry.Date,
                        Note  = timeEntry.Description,
                        Task  = new Task {
                            ID = timeEntry.ToDoItemID != -1 ? FindTask(timeEntry.ToDoItemID) : 0, Project = new Project {
                                ID = FindProject(timeEntry.ProjectID)
                            }
                        },
                        Person = FindUser(timeEntry.PersonID)
                    };

                    timeTrackingEngine.SaveOrUpdate(newTimeSpend, true);
                }
                catch (Exception e)
                {
                    Status.LogError(string.Format(SettingsResource.FailedToSaveTimeSpend, timeEntry.ID), e);
                    LogError(string.Format("time spend '{0}' failed", timeEntry.ID), e);
                }
            }
        }
Esempio n. 3
0
 public static bool CanEditPaymentStatus(TimeSpend timeSpend)
 {
     using (var scope = DIHelper.Resolve())
     {
         return(scope.Resolve <ProjectSecurityTimeTracking>().CanEditPaymentStatus(timeSpend));
     }
 }
Esempio n. 4
0
 public async Task <ActionResult <ControllerResponse <GetTimeSpend> > > Create(CreateTimeSpend createTimeSpend)
 {
     try
     {
         string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.Name).ToString();
         if (null != userId)
         {
             TimeSpend timeSpend = _mapper.Map <TimeSpend>(createTimeSpend);
             timeSpend.UserId = userId;
             return(new ControllerResponse <GetTimeSpend>
             {
                 data = await _timeManager.manageTime(timeSpend)
             });
         }
         else
         {
             return(new ControllerResponse <GetTimeSpend>
             {
                 data = null,
                 message = "UserId error",
                 success = false
             });
         }
     }
     catch (System.Exception)
     {
         return(new ControllerResponse <GetTimeSpend>
         {
             data = null,
             message = "something went wrong, sorry:(",
             success = false
         });
     }
 }
Esempio n. 5
0
 public static void DemandDeleteTimeSpend(TimeSpend timeSpend)
 {
     if (!CanDelete(timeSpend))
     {
         throw CreateSecurityException();
     }
 }
Esempio n. 6
0
 public static void DemandEdit(TimeSpend timeSpend)
 {
     if (!CanEdit(timeSpend))
     {
         throw CreateSecurityException();
     }
 }
Esempio n. 7
0
        public TimeSpend Save(TimeSpend timeSpend)
        {
            using (var db = new DbManager(DatabaseId))
            {
                timeSpend.Date            = TenantUtil.DateTimeToUtc(timeSpend.Date);
                timeSpend.StatusChangedOn = TenantUtil.DateTimeToUtc(timeSpend.StatusChangedOn);

                var insert = Insert(TimeTrackingTable)
                             .InColumnValue("id", timeSpend.ID)
                             .InColumnValue("note", timeSpend.Note)
                             .InColumnValue("date", timeSpend.Date)
                             .InColumnValue("hours", timeSpend.Hours)
                             .InColumnValue("relative_task_id", timeSpend.Task.ID)
                             .InColumnValue("person_id", timeSpend.Person.ToString())
                             .InColumnValue("project_id", timeSpend.Task.Project.ID)
                             .InColumnValue("create_on", timeSpend.CreateOn)
                             .InColumnValue("create_by", CurrentUserID)
                             .InColumnValue("payment_status", timeSpend.PaymentStatus)
                             .InColumnValue("status_changed", timeSpend.StatusChangedOn)
                             .Identity(1, 0, true);

                timeSpend.ID = db.ExecuteScalar <int>(insert);

                return(timeSpend);
            }
        }
Esempio n. 8
0
        private async Task manageStatsAsync(Dictionary <STATS, int> wages, TimeSpend timeSpend)
        {
            DailyStats dailyStats = calculateStats(wages, timeSpend);

            dailyStats.UserId = timeSpend.UserId;
            dailyStats.Date   = DateTime.UtcNow.Date;
            await _dailyStatsService.CreateOrAddAsync(dailyStats);
        }
Esempio n. 9
0
 public static bool CanEditPaymentStatus(TimeSpend timeSpend)
 {
     if (!Can(timeSpend))
     {
         return(false);
     }
     return(IsProjectManager(timeSpend.Task.Project));
 }
Esempio n. 10
0
 public TimeSpend SaveOrUpdate(TimeSpend timeSpend, bool isImport)
 {
     TimeLinePublisher.TimeSpend(timeSpend, timeSpend.Task.Project,
                                 timeSpend.Task,
                                 isImport ? EngineResource.ActionText_Imported : EngineResource.ActionText_Add,
                                 UserActivityConstants.ActivityActionType, UserActivityConstants.SmallActivity);
     return(timeSpendDao.Save(timeSpend));
 }
Esempio n. 11
0
 public static bool CanEdit(TimeSpend timeSpend)
 {
     if (timeSpend == null)
     {
         return(false);
     }
     return(IsProjectManager(timeSpend.Task.Project) || timeSpend.Person == SecurityContext.CurrentAccount.ID);
 }
Esempio n. 12
0
        private async Task manageEnergyAsync(Dictionary <STATS, int> wages, TimeSpend timeSpend)
        {
            DailyEnergy dailyEnergy = calculateEnergy(wages, timeSpend);

            dailyEnergy.UserId = timeSpend.UserId;
            dailyEnergy.Date   = DateTime.UtcNow.Date;
            _logger.LogInformation(dailyEnergy.ToString());
            await _dailyEnergyService.CreateOrAddAsync(dailyEnergy);
        }
Esempio n. 13
0
 public TimeWrapper(TimeSpend timeSpend)
 {
     Date             = (ApiDateTime)timeSpend.Date;
     Hours            = timeSpend.Hours;
     Id               = timeSpend.ID;
     Note             = timeSpend.Note;
     CreatedBy        = EmployeeWraper.Get(timeSpend.Person);
     RelatedProject   = timeSpend.Task.Project.ID;
     RelatedTask      = timeSpend.Task.ID;
     RelatedTaskTitle = timeSpend.Task.Title;
     CanEdit          = ProjectSecurity.CanEdit(timeSpend);
 }
Esempio n. 14
0
 public TimeWrapper(TimeSpend timeSpend)
 {
     Date = (ApiDateTime)timeSpend.Date;
     Hours = timeSpend.Hours;
     Id = timeSpend.ID;
     Note = timeSpend.Note;
     CreatedBy = EmployeeWraper.Get(timeSpend.Person);
     RelatedProject = timeSpend.Task.Project.ID;
     RelatedTask = timeSpend.Task.ID;
     RelatedTaskTitle = timeSpend.Task.Title;
     CanEdit = ProjectSecurity.CanEdit(timeSpend);
 }
Esempio n. 15
0
        public TimeSpend SaveOrUpdate(TimeSpend timeSpend)
        {
            ProjectSecurity.DemandEdit(timeSpend);

            // check guest responsible
            if (ProjectSecurity.IsVisitor(timeSpend.Person))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            timeSpend.CreateOn = DateTime.UtcNow;
            return(timeSpendDao.Save(timeSpend));
        }
Esempio n. 16
0
 public static void TimeSpend(TimeSpend timeSpend, Project project, Task relativeTask, String actionText, int actionType, int businessValue)
 {
     UserActivityPublisher.Publish<TimeLinePublisher>(
      new TimeLineUserActivity(actionText, actionType, businessValue)
      {
          ContentID = relativeTask != null ? relativeTask.ToString() : String.Empty,
          ContainerID = timeSpend.Task.Project.ID.ToString(),
          Title = relativeTask != null ? relativeTask.Title : timeSpend.Hours.ToString(),
          URL = String.Concat(VirtualPathUtility.ToAbsolute(ConfigurationManager.BaseVirtualPath + "timeTracking.aspx"), String.Format("?prjID={0}", timeSpend.Task.Project.ID)),
          AdditionalData = String.Format(AdditionalDataPattern, EntityType.TimeSpend, relativeTask != null ? relativeTask.Title : string.Empty, project.Title),
          SecurityId = string.Format(SecurityDataPattern, EntityType.TimeSpend, relativeTask != null ? relativeTask.ID.ToString() : string.Empty, project.ID)
      });
 }
Esempio n. 17
0
 public static void TimeSpend(TimeSpend timeSpend, Project project, Task relativeTask, String actionText, int actionType, int businessValue)
 {
     UserActivityPublisher.Publish <TimeLinePublisher>(
         new TimeLineUserActivity(actionText, actionType, businessValue)
     {
         ContentID      = relativeTask != null ? relativeTask.ToString() : String.Empty,
         ContainerID    = timeSpend.Task.Project.ID.ToString(),
         Title          = relativeTask != null ? relativeTask.Title : timeSpend.Hours.ToString(),
         URL            = String.Concat(VirtualPathUtility.ToAbsolute(ConfigurationManager.BaseVirtualPath + "timeTracking.aspx"), String.Format("?prjID={0}", timeSpend.Task.Project.ID)),
         AdditionalData = String.Format(AdditionalDataPattern, EntityType.TimeSpend, relativeTask != null ? relativeTask.Title : string.Empty, project.Title),
         SecurityId     = string.Format(SecurityDataPattern, EntityType.TimeSpend, relativeTask != null ? relativeTask.ID.ToString() : string.Empty, project.ID)
     });
 }
Esempio n. 18
0
        private DailyEnergy calculateEnergy(Dictionary <STATS, int> wages, TimeSpend timeSpend)
        {
            switch (timeSpend.ProjectType)
            {
            case (PROJECT_TYPE.ENERGY):
                return(calculateEnergyProjectEnergy(wages, timeSpend.Duration));

            case (PROJECT_TYPE.STATS):
                return(calculateStatsProjectEnergy(wages, timeSpend.Duration));

            default:
                return(null);
            }
        }
Esempio n. 19
0
        public void  SaveOrUpdateTimeSpend()
        {
            IDaoFactory daoFactory = new DaoFactory("projects", 0);

            Project project = daoFactory.GetProjectDao().GetById(5);

            var timeSpend = new TimeSpend
            {
                Date    = ASC.Core.Tenants.TenantUtil.DateTimeNow(),
                Hours   = 10,
                Note    = "asdfasdf",
                Person  = SecurityContext.CurrentAccount.ID,
                Project = project.ID,
            };

            daoFactory.GetTimeSpendDao().Save(timeSpend);
        }
Esempio n. 20
0
        public static bool CanEdit(TimeSpend timeSpend)
        {
            if (!Can(timeSpend))
            {
                return(false);
            }
            if (IsProjectManager(timeSpend.Task.Project))
            {
                return(true);
            }
            if (timeSpend.PaymentStatus == PaymentStatus.Billed)
            {
                return(false);
            }

            return(timeSpend.Person == CurrentUserId || timeSpend.CreateBy == CurrentUserId);
        }
Esempio n. 21
0
        public  void  SaveOrUpdateTimeSpend()
        {
            IDaoFactory daoFactory = new DaoFactory("projects", 0);
            
            Project project = daoFactory.GetProjectDao().GetById(5);
 
            var timeSpend = new TimeSpend
                                {
                                    Date = ASC.Core.Tenants.TenantUtil.DateTimeNow(),
                                    Hours = 10, 
                                    Note = "asdfasdf", 
                                    Person = SecurityContext.CurrentAccount.ID,
                                    Project = project.ID,
                                };

            daoFactory.GetTimeSpendDao().Save(timeSpend);
        }
Esempio n. 22
0
        public TimeSpend Save(TimeSpend timeSpend)
        {
            timeSpend.Date = TenantUtil.DateTimeToUtc(timeSpend.Date);
            var insert = Insert("projects_time_tracking")
                         .InColumns(columns)
                         .Values(
                timeSpend.ID,
                timeSpend.Note,
                timeSpend.Date,
                timeSpend.Hours,
                timeSpend.Task.ID,
                timeSpend.Person.ToString(),
                timeSpend.Task.Project.ID
                )
                         .Identity(1, 0, true);

            timeSpend.ID = DbManager.ExecuteScalar <int>(insert);
            return(timeSpend);
        }
Esempio n. 23
0
        public TimeWrapper(TimeSpend timeSpend)
        {
            Date = (ApiDateTime)timeSpend.Date;
            Hours = timeSpend.Hours;
            Id = timeSpend.ID;
            Note = timeSpend.Note;
            CreatedBy = EmployeeWraper.Get(timeSpend.CreateBy);
            RelatedProject = timeSpend.Task.Project.ID;
            RelatedTask = timeSpend.Task.ID;
            RelatedTaskTitle = timeSpend.Task.Title;
            CanEdit = ProjectSecurity.CanEdit(timeSpend);
            PaymentStatus = timeSpend.PaymentStatus;
            StatusChanged = (ApiDateTime)timeSpend.StatusChangedOn;
            CanEditPaymentStatus = ProjectSecurity.CanEditPaymentStatus(timeSpend);


            if (timeSpend.CreateBy != timeSpend.Person)
            {
                Person = EmployeeWraper.Get(timeSpend.Person);
            }
        }
Esempio n. 24
0
        public async Task <GetTimeSpend> manageTime(TimeSpend timeSpend)
        {
            try
            {
                Dictionary <STATS, int> wages         = timeSpend.getWages();
                List <Task>             managersTasks = new List <Task>();
                managersTasks.Add(Task.Run(() => manageEnergyAsync(wages, timeSpend)));
                managersTasks.Add(Task.Run(() => manageStatsAsync(wages, timeSpend)));
                managersTasks.Add(Task.Run(() => _timeSpendsService.CreateAsync(timeSpend)));
                await Task.WhenAll(managersTasks);

                await _rankManager.manageRank(timeSpend.UserId);

                return(_mapper.Map <GetTimeSpend>(timeSpend));
            }
            catch (Exception e)
            {
                _logger.LogError("Error cached in TimeManager manageTime {error}", e);
                throw e;
            }
        }
Esempio n. 25
0
        public TimeWrapper(TimeSpend timeSpend)
        {
            Date                 = (ApiDateTime)timeSpend.Date;
            Hours                = timeSpend.Hours;
            Id                   = timeSpend.ID;
            Note                 = timeSpend.Note;
            CreatedBy            = EmployeeWraper.Get(timeSpend.CreateBy);
            RelatedProject       = timeSpend.Task.Project.ID;
            RelatedTask          = timeSpend.Task.ID;
            RelatedTaskTitle     = timeSpend.Task.Title;
            CanEdit              = ProjectSecurity.CanEdit(timeSpend);
            PaymentStatus        = timeSpend.PaymentStatus;
            StatusChanged        = (ApiDateTime)timeSpend.StatusChangedOn;
            CanEditPaymentStatus = ProjectSecurity.CanEditPaymentStatus(timeSpend);


            if (timeSpend.CreateBy != timeSpend.Person)
            {
                Person = EmployeeWraper.Get(timeSpend.Person);
            }
        }
Esempio n. 26
0
        public TimeWrapper(ProjectApiBase projectApiBase, TimeSpend timeSpend)
        {
            Date                 = (ApiDateTime)timeSpend.Date;
            Hours                = timeSpend.Hours;
            Id                   = timeSpend.ID;
            Note                 = timeSpend.Note;
            CreatedBy            = projectApiBase.GetEmployeeWraper(timeSpend.CreateBy);
            RelatedProject       = timeSpend.Task.Project.ID;
            RelatedTask          = timeSpend.Task.ID;
            RelatedTaskTitle     = timeSpend.Task.Title;
            CanEdit              = projectApiBase.ProjectSecurity.CanEdit(timeSpend);
            PaymentStatus        = timeSpend.PaymentStatus;
            StatusChanged        = (ApiDateTime)timeSpend.StatusChangedOn;
            CanEditPaymentStatus = projectApiBase.ProjectSecurity.CanEditPaymentStatus(timeSpend);
            Task                 = new TaskWrapper(projectApiBase, timeSpend.Task);
            CreateOn             = (ApiDateTime)timeSpend.CreateOn;

            if (timeSpend.CreateBy != timeSpend.Person)
            {
                Person = projectApiBase.GetEmployeeWraper(timeSpend.Person);
            }
        }
Esempio n. 27
0
        public TimeWrapper AddTaskTime(int taskid, string note, DateTime date, Guid personId, float hours, int projectId)
        {
            if (date == DateTime.MinValue)
            {
                throw new ArgumentException("date can't be empty");
            }
            if (personId == Guid.Empty)
            {
                throw new ArgumentException("person can't be empty");
            }

            var task = EngineFactory.TaskEngine.GetByID(taskid);

            if (task == null)
            {
                throw new ItemNotFoundException();
            }

            if (!EngineFactory.ProjectEngine.IsExists(projectId))
            {
                throw new ItemNotFoundException("project");
            }

            var ts = new TimeSpend
            {
                Date     = date.Date,
                Person   = personId,
                Hours    = hours,
                Note     = note,
                Task     = task,
                CreateBy = SecurityContext.CurrentAccount.ID
            };

            ts = EngineFactory.TimeTrackingEngine.SaveOrUpdate(ts);
            MessageService.Send(Request, MessageAction.TaskTimeCreated, MessageTarget.Create(ts.ID), task.Project.Title, task.Title, ts.Note);

            return(TimeWrapperSelector(ts));
        }
Esempio n. 28
0
        public TimeWrapper AddTaskTime(int taskid, string note, DateTime date, Guid personId, float hours, int projectId)
        {
            if (date == DateTime.MinValue)
            {
                throw new ArgumentException("date can't be empty");
            }
            if (personId == Guid.Empty)
            {
                throw new ArgumentException("person can't be empty");
            }

            var task = EngineFactory.GetTaskEngine().GetByID(taskid);

            if (task == null)
            {
                throw new ItemNotFoundException();
            }

            if (!EngineFactory.GetProjectEngine().IsExists(projectId))
            {
                throw new ItemNotFoundException("project");
            }

            var ts = new TimeSpend
            {
                Date   = date.Date,
                Person = personId,
                Hours  = hours,
                Note   = note,
                Task   = task
            };

            EngineFactory.GetTimeTrackingEngine().SaveOrUpdate(ts);

            return(new TimeWrapper(ts));
        }
Esempio n. 29
0
 protected TimeSpend Get(TimeSpend timeSpend)
 {
     return(TimeTrackingEngine.GetByID(timeSpend.ID));
 }
Esempio n. 30
0
 public TimeSpend SaveOrUpdate(TimeSpend timeSpend, bool isImport)
 {
     TimeLinePublisher.TimeSpend(timeSpend, timeSpend.Task.Project,
                                 timeSpend.Task,
                                 isImport ? EngineResource.ActionText_Imported : EngineResource.ActionText_Add,
                                 UserActivityConstants.ActivityActionType, UserActivityConstants.SmallActivity);
     return timeSpendDao.Save(timeSpend);
 }
Esempio n. 31
0
        private void SaveTimeSpends(ITimeEntry[] timeEntries)
        {
            TimeTrackingEngine timeTrackingEngine = _engineFactory.GetTimeTrackingEngine();
            foreach (var timeEntry in timeEntries)
            {
                try
                {
                    TimeSpend newTimeSpend = new TimeSpend()
                                                 {
                                                     Hours = (float)timeEntry.Hours,
                                                     Date = timeEntry.Date,
                                                     Note = timeEntry.Description,
                                                     Task = new Task { ID = timeEntry.ToDoItemID != -1 ? FindTask(timeEntry.ToDoItemID) : 0, Project = new Project { ID = FindProject(timeEntry.ProjectID) } },
                                                     Person = FindUser(timeEntry.PersonID)
                                                 };

                    timeTrackingEngine.SaveOrUpdate(newTimeSpend, true);
                }
                catch (Exception e)
                {
                    Status.LogError(string.Format(SettingsResource.FailedToSaveTimeSpend, timeEntry.ID), e);
                    LogError(string.Format("time spend '{0}' failed", timeEntry.ID), e);
                }
            }
        }
Esempio n. 32
0
 protected void Delete(TimeSpend timeSpend)
 {
     TimeTrackingEngine.Delete(timeSpend);
 }
Esempio n. 33
0
 public TimeSpend Save(TimeSpend timeSpend)
 {
     timeSpend.Date = TenantUtil.DateTimeToUtc(timeSpend.Date);
     var insert = Insert("projects_time_tracking")
         .InColumns(columns)
         .Values(
             timeSpend.ID,
             timeSpend.Note,
             timeSpend.Date,
             timeSpend.Hours,
             timeSpend.Task.ID,
             timeSpend.Person.ToString(),
             timeSpend.Task.Project.ID
         )
         .Identity(1, 0, true);
     timeSpend.ID = DbManager.ExecuteScalar<int>(insert);
     return timeSpend;
 }
Esempio n. 34
0
        public TimeSpend ChangePaymentStatus(TimeSpend timeSpend, PaymentStatus newStatus)
        {
            if (!ProjectSecurity.CanEditPaymentStatus(timeSpend)) throw new SecurityException("Access denied.");

            if (timeSpend == null) throw new ArgumentNullException("timeSpend");

            var task = taskDao.GetById(timeSpend.Task.ID);

            if (task == null) throw new Exception("Task can't be null.");

            ProjectSecurity.DemandEdit(timeSpend);

            if (timeSpend.PaymentStatus == newStatus) return timeSpend;

            timeSpend.PaymentStatus = newStatus;

            return timeSpendDao.Save(timeSpend);
        }
 public static bool CanEditPaymentStatus(TimeSpend timeSpend)
 {
     return Can(timeSpend) && IsProjectManager(timeSpend.Task.Project);
 }
Esempio n. 36
0
 public TimeSpend SaveOrUpdate(TimeSpend timeSpend)
 {
     return SaveOrUpdate(timeSpend, false);
 }
Esempio n. 37
0
        public TimeSpend Save(TimeSpend timeSpend)
        {
            using (var db = new DbManager(DatabaseId))
            {
                timeSpend.Date = TenantUtil.DateTimeToUtc(timeSpend.Date);
                timeSpend.StatusChangedOn = TenantUtil.DateTimeToUtc(timeSpend.StatusChangedOn);

                var insert = Insert(TimeTrackingTable)
                    .InColumnValue("id", timeSpend.ID)
                    .InColumnValue("note", timeSpend.Note)
                    .InColumnValue("date", timeSpend.Date)
                    .InColumnValue("hours", timeSpend.Hours)
                    .InColumnValue("relative_task_id", timeSpend.Task.ID)
                    .InColumnValue("person_id", timeSpend.Person.ToString())
                    .InColumnValue("project_id", timeSpend.Task.Project.ID)
                    .InColumnValue("create_on", timeSpend.CreateOn)
                    .InColumnValue("create_by", CurrentUserID)
                    .InColumnValue("payment_status", timeSpend.PaymentStatus)
                    .InColumnValue("status_changed", timeSpend.StatusChangedOn)
                    .Identity(1, 0, true);

                timeSpend.ID = db.ExecuteScalar<int>(insert);

                return timeSpend;
            }
        }
Esempio n. 38
0
 public void Delete(TimeSpend timeSpend)
 {
     ProjectSecurity.DemandDelete(timeSpend);
     DaoFactory.TimeSpendDao.Delete(timeSpend.ID);
 }
Esempio n. 39
0
 public static bool CanEditPaymentStatus(TimeSpend timeSpend)
 {
     return(Can(timeSpend) && IsProjectManager(timeSpend.Task.Project));
 }
Esempio n. 40
0
 public static bool CanEdit(TimeSpend timeSpend)
 {
     if (timeSpend == null) return false;
     return IsProjectManager(timeSpend.Task.Project) || timeSpend.Person == SecurityContext.CurrentAccount.ID;
 }
Esempio n. 41
0
        public TimeSpend SaveOrUpdate(TimeSpend timeSpend)
        {
            ProjectSecurity.DemandEdit(timeSpend);

            // check guest responsible
            if (ProjectSecurity.IsVisitor(timeSpend.Person))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            timeSpend.CreateOn = DateTime.UtcNow;
            return timeSpendDao.Save(timeSpend);
        }
Esempio n. 42
0
 public void Delete(TimeSpend timeSpend)
 {
     ProjectSecurity.DemandDeleteTimeSpend(timeSpend);
     timeSpendDao.Delete(timeSpend.ID);
 }
        public static bool CanDelete(TimeSpend timeSpend)
        {
            if (!Can(timeSpend)) return false;
            if (IsProjectManager(timeSpend.Task.Project)) return true;
            if (timeSpend.PaymentStatus == PaymentStatus.Billed) return false;

            return IsInTeam(timeSpend.Task.Project) &&
                   (timeSpend.CreateBy == CurrentUserId || timeSpend.Person == CurrentUserId);
        }
        public TimeWrapper AddTaskTime(int taskid, string note, DateTime date, Guid personId, float hours, int projectId)
        {
            if (date == DateTime.MinValue) throw new ArgumentException("date can't be empty");
            if (personId == Guid.Empty) throw new ArgumentException("person can't be empty");

            var task = EngineFactory.GetTaskEngine().GetByID(taskid);

            if (task == null) throw new ItemNotFoundException();

            if (!EngineFactory.GetProjectEngine().IsExists(projectId)) throw new ItemNotFoundException("project");

            var ts = new TimeSpend
                {
                    Date = date.Date,
                    Person = personId,
                    Hours = hours,
                    Note = note,
                    Task = task
                };

            ts = EngineFactory.GetTimeTrackingEngine().SaveOrUpdate(ts);
            MessageService.Send(_context, MessageAction.TaskTimeCreated, task.Project.Title, task.Title, ts.Note);

            return new TimeWrapper(ts);
        }
 public static void DemandEdit(TimeSpend timeSpend)
 {
     if (!CanEdit(timeSpend)) throw CreateSecurityException();
 }
Esempio n. 46
0
 public static bool CanEditPaymentStatus(TimeSpend timeSpend)
 {
     if (!Can(timeSpend)) return false;
     return IsProjectManager(timeSpend.Task.Project);
 }
 public static void DemandDeleteTimeSpend(TimeSpend timeSpend)
 {
     if (!CanDelete(timeSpend)) throw CreateSecurityException();
 }
Esempio n. 48
0
 public bool CanEditPaymentStatus(TimeSpend timeSpend)
 {
     return(Scope.Resolve <ProjectSecurityTimeTracking>().CanEditPaymentStatus(timeSpend));
 }
Esempio n. 49
0
 public void Delete(TimeSpend timeSpend)
 {
     ProjectSecurity.DemandDeleteTimeSpend(timeSpend);
     timeSpendDao.Delete(timeSpend.ID);
 }