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); } } }
public static bool CanEditPaymentStatus(TimeSpend timeSpend) { using (var scope = DIHelper.Resolve()) { return(scope.Resolve <ProjectSecurityTimeTracking>().CanEditPaymentStatus(timeSpend)); } }
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 }); } }
public static void DemandDeleteTimeSpend(TimeSpend timeSpend) { if (!CanDelete(timeSpend)) { throw CreateSecurityException(); } }
public static void DemandEdit(TimeSpend timeSpend) { if (!CanEdit(timeSpend)) { throw CreateSecurityException(); } }
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); } }
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); }
public static bool CanEditPaymentStatus(TimeSpend timeSpend) { if (!Can(timeSpend)) { return(false); } return(IsProjectManager(timeSpend.Task.Project)); }
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)); }
public static bool CanEdit(TimeSpend timeSpend) { if (timeSpend == null) { return(false); } return(IsProjectManager(timeSpend.Task.Project) || timeSpend.Person == SecurityContext.CurrentAccount.ID); }
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); }
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); }
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)); }
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) }); }
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) }); }
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); } }
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); }
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); }
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); }
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); } }
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; } }
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); } }
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)); }
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)); }
protected TimeSpend Get(TimeSpend timeSpend) { return(TimeTrackingEngine.GetByID(timeSpend.ID)); }
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); }
protected void Delete(TimeSpend timeSpend) { TimeTrackingEngine.Delete(timeSpend); }
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; }
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); }
public TimeSpend SaveOrUpdate(TimeSpend timeSpend) { return SaveOrUpdate(timeSpend, false); }
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; } }
public void Delete(TimeSpend timeSpend) { ProjectSecurity.DemandDelete(timeSpend); DaoFactory.TimeSpendDao.Delete(timeSpend.ID); }
public static bool CanEditPaymentStatus(TimeSpend timeSpend) { return(Can(timeSpend) && IsProjectManager(timeSpend.Task.Project)); }
public static bool CanEdit(TimeSpend timeSpend) { if (timeSpend == null) return false; return IsProjectManager(timeSpend.Task.Project) || timeSpend.Person == SecurityContext.CurrentAccount.ID; }
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); }
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(); }
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(); }
public bool CanEditPaymentStatus(TimeSpend timeSpend) { return(Scope.Resolve <ProjectSecurityTimeTracking>().CanEditPaymentStatus(timeSpend)); }