示例#1
0
        public ActionResult Create(int?hourId)
        {
            var model = new TaskFormModel();

            try
            {
                Task task;

                if (hourId != null)
                {
                    task = TaskService.TaskNew(HourService.HourFetch((int)hourId));
                }
                else
                {
                    task = TaskService.TaskNew();
                }

                this.MapToModel(task, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(this.View(model));
        }
示例#2
0
        public static Hour CreateHourThatIsArchivedAndLogon(string userName, string userPassword)
        {
            var name     = DataHelper.RandomString(20);
            var password = DataHelper.RandomString(20);

            BusinessHelper.CreateUserWithFullControl(name, password);

            BusinessPrincipal.Login(name, password);

            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.TaskId     = task.TaskId;
            hour.Date       = DateTime.Now.Date;
            hour.Duration   = 8;
            hour.Notes      = DataHelper.RandomString(100);
            hour.IsArchived = true;

            hour = HourService.HourSave(hour);

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login(userName, userPassword);

            return(hour);
        }
示例#3
0
        public void Hour_New()
        {
            var hour = HourService.HourNew();

            Assert.IsTrue(hour.IsNew, "IsNew should be true");
            Assert.IsTrue(hour.IsDirty, "IsDirty should be true");
            Assert.IsFalse(hour.IsValid, "IsValid should be false");
            Assert.IsTrue(hour.IsSelfDirty, "IsSelfDirty should be true");
            Assert.IsFalse(hour.IsSelfValid, "IsSelfValid should be false");
            Assert.IsFalse(hour.IsArchived, "IsArchived should be false");
            Assert.IsTrue(hour.UserId == BusinessPrincipal.GetCurrentIdentity().UserId,
                          string.Format("UserId should be '{0}'", BusinessPrincipal.GetCurrentIdentity().UserId));
            Assert.IsTrue(hour.Date == DateTime.Now.Date,
                          string.Format("Date should be '{0:d}'", DateTime.Now.Date));

            // we init some values, so we want to make sure the rules are captured so
            // we reset the values to default
            hour.UserId = 0;
            hour.Date   = DateTime.MaxValue.Date;

            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Int32, "ProjectId"),
                          "ProjectId should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Int32, "UserId"),
                          "UserId should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.DateTime, "Date"),
                          "Date should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Decimal, "Duration"),
                          "Duration should be required");
        }
示例#4
0
        public ActionResult Create(TaskFormModel model)
        {
            var task = TaskService.TaskNew();

            this.MapToObject(model, task);

            task = TaskService.TaskSave(task);

            if (task.IsValid)
            {
                if (model.HourId != 0)
                {
                    var hour = HourService.HourFetch(model.HourId);

                    hour.TaskId = task.TaskId;

                    HourService.HourSave(hour);
                }

                return(new JsonResult {
                    Data = this.Url.Action("Edit", new { id = task.TaskId, message = Resources.SaveSuccessfulMessage })
                });
            }

            this.MapToModel(task, model, false);

            return(this.View(model));
        }
示例#5
0
        public void Hour_Edit()
        {
            var hour  = HourService.HourNew();
            var notes = DataHelper.RandomString(100);

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = notes;

            Assert.IsTrue(hour.IsValid, "IsValid should be true");

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            hour.Notes = DataHelper.RandomString(100);

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            Assert.IsTrue(hour.Notes != notes, "Notes should have different value");
        }
示例#6
0
        public ActionResult Create(int?projectId, int?taskId)
        {
            var model = new HourFormModel();

            try
            {
                var hour = HourService.HourNew();

                if (projectId.HasValue &&
                    projectId.Value != 0)
                {
                    hour.ProjectId = projectId.Value;
                }

                if (taskId.HasValue &&
                    taskId.Value != 0)
                {
                    hour.TaskId = taskId.Value;
                }

                this.Map(hour, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(this.View(model));
        }
示例#7
0
        public void Hour_Fetch_List()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = DataHelper.RandomString(100);

            HourService.HourSave(hour);

            hour = HourService.HourNew();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = DataHelper.RandomString(100);

            HourService.HourSave(hour);

            var hours = HourService.HourFetchInfoList();

            Assert.IsTrue(hours.Count > 1, "Hours should be greater than one");
        }
示例#8
0
        public ActionResult Index(int[] projectId, int[] userId, int[] taskId, string date, int?isArchived, string label, string sortBy, string sortOrder, FormCollection collection)
        {
            if (collection["HourId"] != null)
            {
                var action  = collection["Action"];
                var hourIds = collection["HourId"]
                              .Split(',')
                              .Select(hourId => int.Parse(hourId))
                              .ToList();

                switch (action)
                {
                case "Archive":
                    HourService.HourArchive(hourIds.ToArray());
                    break;

                case "Unarchive":
                    HourService.HourUnarchive(hourIds.ToArray());
                    break;

                default:
                    break;
                }
            }

            return(this.RedirectToAction("Index", new { isArchived = 1, sortBy, sortOrder }));
        }
示例#9
0
        public void Hour_Delete()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = DataHelper.RandomString(100);

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            HourService.HourDelete(hour.HourId);

            try
            {
                HourService.HourFetch(hour.HourId);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetBaseException() is InvalidOperationException);
            }
        }
示例#10
0
        public ActionResult Index(string dashboard)
        {
            var model = new HomeIndexModel();

            model.Tab       = "Home";
            model.Dashboard = dashboard ?? "My";
            model.StartDate = DateTime.Today.ToStartOfWeek();
            model.EndDate   = DateTime.Today.ToEndOfWeek();

            if (model.Dashboard == "Team")
            {
                model.Tasks = TaskService.TaskFetchInfoList(
                    new TaskCriteria
                {
                    IsArchived = false
                });
                model.Hours = HourService.HourFetchInfoList(model.StartDate, model.EndDate);
                model.Feeds = FeedService.FeedFetchInfoList(5);
            }
            else
            {
                model.Tasks = MyService.TaskFetchInfoList();
                model.Hours = MyService.HourFetchInfoList(model.StartDate, model.EndDate);
                model.Feeds = MyService.FeedFetchInfoList(5);
            }

            return(this.View(model));
        }
示例#11
0
 public HomeController(ApplicationDbContext context, ProjectService project, EmployeeService employee, HourService hour, IConfiguration config)
 {
     _context         = context;
     _projectService  = project;
     _employeeService = employee;
     _hourService     = hour;
     _config          = config;
 }
示例#12
0
        public ActionResult Index(int[] projectId, int[] userId, int[] taskId, string date, int?isArchived, string label, string text, string sortBy, string sortOrder)
        {
            var model = new HourIndexModel();

            model.Tab          = "Hour";
            model.FindText     = text;
            model.FindCategory = "Hour";

            model.Projects           = DataHelper.GetProjectList();
            model.ProjectId          = projectId ?? new int[0];
            model.ProjectName        = DataHelper.ToString(model.Projects, model.ProjectId, "any project");
            model.ProjectDisplayName = DataHelper.Clip(model.ProjectName, 40);

            model.Users           = DataHelper.GetUserList();
            model.UserId          = userId ?? new int[0];
            model.UserName        = DataHelper.ToString(model.Users, model.UserId, "any user");
            model.UserDisplayName = DataHelper.Clip(model.UserName, 20);

            model.Label      = label;
            model.Date       = date ?? string.Empty;
            model.IsArchived = isArchived ?? 1;

            model.Filters = MyService.FilterFetchInfoList("Hour");

            model.SortBy    = sortBy ?? "Date";
            model.SortOrder = sortOrder ?? "DESC";
            model.SortableColumns.Add("Date", "Date");
            model.SortableColumns.Add("ProjectName", "Project");
            model.SortableColumns.Add("UserName", "User");

            model.LabelByCountListModel =
                new LabelByCountListModel
            {
                Action = "Hour",
                Label  = label,
                Labels = DataHelper.GetTaskLabelByCountList()
            };

            var criteria = new HourCriteria()
            {
                ProjectId  = projectId,
                UserId     = userId,
                TaskId     = taskId,
                Date       = new DateRangeCriteria(model.Date),
                IsArchived = DataHelper.ToBoolean(isArchived, false),
                TaskLabels = string.IsNullOrEmpty(label) ? null : new[] { label },
                Text       = text
            };

            var hours = HourService.HourFetchInfoList(criteria)
                        .AsQueryable();

            hours = hours.OrderBy(string.Format("{0} {1}", model.SortBy, model.SortOrder));

            model.Hours = hours;

            return(this.View(model));
        }
 public EmployeesController(ApplicationDbContext context, ProjectService project, EmployeeService employee, HourService hour, AccessLevelService accessLevel, Files files, IHostingEnvironment env)
 {
     _context            = context;
     _projectService     = project;
     _employeeService    = employee;
     _hourService        = hour;
     _accessLevelService = accessLevel;
     _files          = files;
     _appEnvironment = env;
 }
 public ProjectsController(ApplicationDbContext context, ProjectService project, EmployeeService employee, HourService hour, AccessLevelService accessLevel, ClientService client, IHostingEnvironment env)
 {
     _context            = context;
     _context            = context;
     _projectService     = project;
     _employeeService    = employee;
     _hourService        = hour;
     _accessLevelService = accessLevel;
     _appEnvironment     = env;
     _clientService      = client;
 }
示例#15
0
 public OutlaysController(ApplicationDbContext context, EmployeeService employeeService, ProjectService projectService, HourService hourService, AccessLevelService accessLevelService, ClientService clientService, OutlaysService outlaysService, Files files, IHostingEnvironment appEnvironment)
 {
     _context            = context;
     _employeeService    = employeeService;
     _projectService     = projectService;
     _hourService        = hourService;
     _accessLevelService = accessLevelService;
     _clienteService     = clientService;
     _outlaysService     = outlaysService;
     _files          = files;
     _appEnvironment = appEnvironment;
 }
 public ModeAdminController(ApplicationDbContext context, ProjectService project, EmployeeService employee, HourService hour, ProjectTeamService projectTeam, ClientService client, Files files, IConfiguration config, IHostingEnvironment env)
 {
     _context            = context;
     _projectService     = project;
     _projectTeamService = projectTeam;
     _employeeService    = employee;
     _hourService        = hour;
     _clientService      = client;
     _files          = files;
     _config         = config;
     _appEnvironment = env;
 }
示例#17
0
        public void Hour_New()
        {
            Exception exception = null;

            try
            {
                HourService.HourNew();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception == null, "Exception should be null");
        }
示例#18
0
        public static Hour CreateHour()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.TaskId   = task.TaskId;
            hour.Date     = DateTime.Now.Date;
            hour.Duration = 8;
            hour.Notes    = DataHelper.RandomString(100);

            hour = HourService.HourSave(hour);

            return(hour);
        }
        public void Hour_New()
        {
            Exception exception = null;

            try
            {
                HourService.HourNew();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException);
        }
示例#20
0
        public void Hour_Add()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = DataHelper.RandomString(100);

            Assert.IsTrue(hour.IsValid, "IsValid should be true");

            hour = HourService.HourSave(hour);
        }
示例#21
0
        public ActionResult Delete(int id)
        {
            var model = new HourFormModel();

            try
            {
                var hour = HourService.HourFetch(id);

                this.Map(hour, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(this.View(model));
        }
示例#22
0
        public void Hour_Fetch()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = DataHelper.RandomString(100);

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            Assert.IsFalse(hour == null, "Hour should not be null");
        }
        public void Hour_Fetch()
        {
            var hour = BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleReview.UserName,
                HourTestsWithRoleReview.UserPassword);

            Exception exception = null;

            try
            {
                HourService.HourFetch(hour.HourId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception == null, "Exception should be null");
        }
示例#24
0
        public ActionResult Create(int?projectId, int?taskId, HourFormModel model)
        {
            var hour = HourService.HourNew();

            Csla.Data.DataMapper.Map(model, hour, true);

            hour = HourService.HourSave(hour);

            if (hour.IsValid)
            {
                return(new JsonResult {
                    Data = this.Url.Action("Edit", new { id = hour.HourId, message = Resources.SaveSuccessfulMessage })
                });
            }

            this.Map(hour, model, false);

            return(this.View(model));
        }
示例#25
0
        public void Hour_Cannot_Delete_Where_Is_Archived_Property_Is_True()
        {
            var hour = BusinessHelper.CreateHourThatIsArchivedAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword);

            Exception exception = null;

            try
            {
                HourService.HourDelete(hour);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException, "Exception should be of type SecurityException");
        }
示例#26
0
        public void Hour_Delete()
        {
            var hour = BusinessHelper.CreateHourForUserAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword,
                HourTestsWithRoleContribute.User.UserId);

            Exception exception = null;

            try
            {
                HourService.HourDelete(hour.HourId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception == null, "Exception should be null");
        }
示例#27
0
        public void Hour_Cannot_Delete_Record_For_Different_User()
        {
            var hour = BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword);

            Exception exception = null;

            try
            {
                HourService.HourDelete(hour.HourId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException, "Exception should be of type SecurityException");
        }
        public void Hour_Delete()
        {
            var hour = BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleReview.UserName,
                HourTestsWithRoleReview.UserPassword);

            Exception exception = null;

            try
            {
                HourService.HourDelete(hour.HourId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException);
        }
示例#29
0
        public ActionResult Edit(int id, HourFormModel model)
        {
            var hour = HourService.HourFetch(id);

            Csla.Data.DataMapper.Map(model, hour, true);

            hour = HourService.HourSave(hour);

            if (hour.TaskId != 0)
            {
                model.Task = TaskService.TaskFetch(hour.TaskId);
            }

            if (hour.IsValid)
            {
                model.Message = Resources.SaveSuccessfulMessage;
            }

            this.Map(hour, model, true);

            return(this.View(model));
        }
示例#30
0
        public void Hour_Fetch_List()
        {
            BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword);

            BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword);

            Exception exception = null;

            try
            {
                HourService.HourFetchInfoList();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception == null, "Exception should be null");
        }