public bool Handle(EditProjectsCommand command) { using (TransactionScope transaction = new TransactionScope()) { try { var project = timeSheetDbContext .Set <Project>() .SingleOrDefault(x => x.Id == command.ProjectId); UpdateProject(project, command); if (command.File != null) { var fileId = AddFile(command.File); if (project.IconId.HasValue) { RemoveOldIcon(project.IconId.Value); } project.IconId = fileId; timeSheetDbContext.SaveChanges(); } transaction.Complete(); return(true); } catch (Exception) { return(false); } } }
public string Handle(DeleteTaskCommand command) { var task = timeSheetDbContext.Set <WorkTime>().Where(x => x.TimeId == command.TaskId); timeSheetDbContext.Set <WorkTime>().RemoveRange(task); timeSheetDbContext.SaveChanges(); return("Add successfully"); }
private Guid AddIcon(File file) { file = timeSheetDbContext .Set <File>() .Add(file); timeSheetDbContext.SaveChanges(); return(file.Id); }
public File Handle(GetFileByFileIdQuery query) { return(timeSheetDbContext .Set <File>() .Where(f => f.Id == query.FileId) .SingleOrDefault()); }
public Project[] Handle(GetListProjectsQuery query) { var searchText = string.IsNullOrEmpty(query.SearchText) ? "%%" : $"%{query.SearchText}%"; var rawQuery = @" SELECT Id ,Name ,ClientName ,Status ,StartDate ,IconId ,ProjectOwner ,Description FROM TR.Projects P WHERE P.Name LIKE @SearchText OR P.ProjectOwner LIKE @SearchText OR P.ClientName LIKE @SearchText;"; var parameters = new SqlParameter[] { new SqlParameter("@SearchText", searchText) }; return(timeSheetDbContext .Set <Project>() .SqlQuery(rawQuery, parameters) .ToArray()); }
public TimeSheet[] Handle(GetTimeSheetDetailQuery command) { var result = from w in timeSheetDbContext.Set <WorkTime>() join p in timeSheetDbContext.Set <Project>() on w.ProjectId equals p.Id where (w.EmployeeId == command.UserId) && (w.Time == command.SingleDate) select new TimeSheet { ProjectName = p.Name, Hours = w.Hours, Task = w.Task, WorkTimeId = w.TimeId }; return(result.OrderBy(x => x.ProjectName).ToArray()); }
public bool Handle(UpdateUserProfileCommand command) { using (TransactionScope transaction = new TransactionScope()) { try { var user = manageUsersDbContext .Set <TRUser>() .SingleOrDefault(x => x.Id == command.UserId); var currentAvt = timeSheetDbContext .Set <File>() .SingleOrDefault(x => x.Id == user.AvartarId); user.FirstName = command.FirstName; user.LastName = command.LastName; user.EnglishName = command.EnglishName; user.Gender = command.Gender; user.DOB = command.DOB; user.IdNumber = command.IdNumber; manageUsersDbContext.SaveChanges(); if (command.File != null) { var fileId = AddFile(command.File); if (user.AvartarId != Guid.Empty) { RemoveOldIcon(user.AvartarId); } user.AvartarId = fileId; timeSheetDbContext.SaveChanges(); manageUsersDbContext.SaveChanges(); } transaction.Complete(); return(true); } catch (Exception) { return(false); } } }
public Project[] Handle(GetProjectsQuery query) { var projects = timeSheetDbContext .Set <Project>() .ToArray(); if (projects == null) { return(new Project[0]); } return(projects); }
public string Handle(UploadFileCommand command) { try { timeSheetDbContext.Set <File>().Add(command.File); timeSheetDbContext.SaveChanges(); return("Success"); } catch (Exception ex) { return(ex.Message); } }
public string Handle(EditWorkTimeCommand command) { var workTime = timeSheetDbContext .Set <WorkTime>() .SingleOrDefault(x => x.TimeId == command.Id); workTime.Hours = command.Hours; workTime.ProjectId = command.ProjectId; workTime.Task = command.Tasks; timeSheetDbContext.SaveChanges(); return("Edit successfully"); }
public TimeSheet[] Handle(FilterTimeSheetByDateRangeQuery command) { var result = timeSheetDbContext.Set <WorkTime>() .Where(x => x.Time >= command.StartDate) .Where(y => y.Time <= command.EndDate) .Where(x => x.EmployeeId == command.UserId) .GroupBy(x => x.Time) .Select(w => new TimeSheet { TotalHours = w.Sum(x => x.Hours), Date = w.FirstOrDefault().Time }).ToArray(); return(result); }
public Equipment[] Handle(GetEquipmentsOfEmployeeQuery query) { var equipments = timeSheetDbContext .Set <Equipment>() .Where(x => x.AssignTo == query.UserId) .OrderByDescending(x => x.AssignOn) .ToArray(); if (equipments == null) { return(new Equipment[0]); } return(equipments); }
public WorkTime Handle(AddWorkTimeCommand command) { WorkTime worktime = new WorkTime() { ProjectId = command.ProjectId, Hours = command.Hours, Task = command.Tasks, TimeId = Guid.NewGuid(), Time = command.AddedDate, EmployeeId = command.UserId }; timeSheetDbContext.Set <WorkTime>().Add(worktime); timeSheetDbContext.SaveChanges(); return(worktime); }
public TimeSheet[] Handle(GetListTimeSheetQuery command) { var timeSheetList = new List <TimeSheet>(); for (DateTime i = command.StartDate; i <= command.EndDate; i = i.AddDays(1)) { timeSheetList.Add(new TimeSheet { Date = i.Date, TotalHours = 0 }); } var workTime = timeSheetDbContext .Set <WorkTime>() .Where(x => x.Time >= command.StartDate && x.Time <= command.EndDate && x.EmployeeId == command.UserId) .GroupBy(x => x.Time) .Select(w => new TimeSheet { TotalHours = w.Sum(x => x.Hours), Date = w.FirstOrDefault().Time }).ToList(); foreach (var item in timeSheetList) { var data = workTime .Where(n => n.Date == item.Date) .SingleOrDefault(); if (data != null) { item.TotalHours = data.TotalHours; } } return(timeSheetList.ToArray()); }
public Equipment[] Handle(GetEquipmentQuery command) { return(timesheetreportContext.Set <Equipment>().OrderByDescending(x => x.CreatedOn).ToArray()); }
public Project Handle(GetProjectQuery query) { return(timeSheetDbContext .Set <Project>() .SingleOrDefault(p => p.Id == query.ProjectId)); }