示例#1
0
        public void TestBasicAddRemoveUser()
        {
            IConfiguration config = getTestConfiguration();

            using (var context = new SGContext(config))
            {
                var adminTask = LoginTokenTasks.LoginAsync(context, Defaults.UserAdmin, Defaults.UserAdminPassword);
                adminTask.Wait();
                var admin = adminTask.Result;

                var userA = TryCreateUser(context, admin, "user@localhost", "pwd");
                Assert.IsNotNull(userA, "Failed to create a valid user user@localhost");
                var userB = TryCreateUser(context, admin, "user@localhost", "pwd");
                Assert.IsNull(userB, "Incorrectly succeeded in creating a user that already exists.");

                var userC = TryCreateUser(context, admin, "user2@localhost", "pwd");
                Assert.IsNotNull(userA, "Failed to create a valid user user2@localhost");

                TryChangeUserDisplayEmailAndName(context, admin, userA, "userA@localhost", "User A new name");

                var userTask = UserTasks.QuickGetUserNoAuthCheckAsync(context, "userA@localhost");
                userTask.Wait();
                var userA_2 = userTask.Result;

                Assert.IsNotNull(userA_2, "User failed to be retrieved after email update");
                Assert.AreEqual(userA_2.Id, userA.Id, "User that came back after email change had a different ID.");
                Assert.AreEqual(userA_2.DisplayName, "User A new name", "Displayname update failed.");
            }
        }
示例#2
0
        public JsonResult SetTask(int id, string UserTaskDate)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                var task = new UserTask();

                task.ID             = id;
                task.UserTaskDate   = Utilities.ToEnglishDate(UserTaskDate);
                task.UserTaskStatus = UserTaskStatus.NotDone;

                UserTasks.UpdateDateTask(task);

                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
示例#3
0
      public IActionResult Post([FromBody] TaskDTO _task)
      {
          System.Diagnostics.Trace.WriteLine("CREATE TASK");
          System.Diagnostics.Trace.WriteLine(_task.isImportant);
          Models.Task task = new Models.Task {
              TaskName       = _task.TaskName,
              TaskDesription = _task.TaskDesription,
              TaskCategory   = _context.TaskCategory.Find(_task.CategoryID),
              DateAdded      = DateTime.Now,
              isImportant    = _task.isImportant,
              Deadline       = _task.Deadline
          };

          try
          {
              _context.Task.Add(task);
              _context.SaveChanges();
              UserTasks ut = new UserTasks
              {
                  Task = _context.Task.Find(task.Id),
                  User = _context.User.Find(long.Parse(User.Identity.Name))
              };
              _context.UserTasks.Add(ut);
              _context.SaveChanges();
              return(Ok());
          }
          catch (ApplicationException ex)
          {
              return(BadRequest(new { message = ex.Message }));
          }
      }
        private Task StartBusinessCardProcessing(string exportFormat, Options options)
        {
            var task = new UserTask(options.SourcePath)
            {
                TaskStatus      = "Uploading",
                OutputFilePaths = new Dictionary <string, string>
                {
                    [exportFormat] = Path.Combine(options.TargetPath, $"{options.FileName}.{exportFormat.ToExtension()}"),
                },
                TargetFormat = exportFormat,
            };

            UserTasks.Add(task);

            var bcrOptions = new Options
            {
                SourcePath   = options.SourcePath,
                TargetPath   = options.TargetPath,
                Mode         = options.Mode,
                Language     = options.Language,
                OutputFormat = exportFormat,
            };

            return(SafeInvokeProcessorCommands(_processor.ProcessPathAsync(bcrOptions, task), task));
        }
        public void Delete_TaskFromFave(int taskID)
        {
            var taskName = Tasks.Where(t => t.ID == taskID).Select(t => t.TaskName).FirstOrDefault();

            WriteLog(taskID, taskName, DateTime.Now, "DELETE_FAVE");

            UserTask userTaskDB = UserTasks.Where(t => t.TaskID == taskID && t.UserID == GlobalInfo.CurrentUser.ID).FirstOrDefault();

            //List<Task> childTasksBD = (from t in Tasks where t.ParentTaskID == taskID select t).ToList();
            //foreach (var t in childTasksBD)
            //    t.ParentTaskID = taskBD.ParentTaskID; //зачем-то переподцеплять детей к родителю. Удаляем, так удаляем и поддерево!

            //List<Work> worksBD = (from w in Works where w.TaskID == taskID select w).ToList();
            //foreach (var w in worksBD)
            //{
            //    Delete_AttrValuesFields_ForWork(w.ID);
            //    Works.Remove(w);
            //}
            ChangeTracker.DetectChanges();

            if (userTaskDB != null)
            {
                UserTasks.Remove(userTaskDB);
            }
            SaveChanges();
        }
示例#6
0
 public MainWindowViewModel()
 {
     foreach (var userTask in UserTasks.Where(userTask => !Groups.Contains(userTask.Group)))
     {
         Groups.Add(userTask.Group);
     }
 }
        /// <summary>
        /// 將ViewModel 使用的工作紀錄屬性物件,更新到 API 的工作紀錄模型資料上
        /// </summary>
        /// <param name="userTaskVM"></param>
        /// <returns></returns>
        UserTasks UpdateUserTasks(UserTasksVM userTaskVM)
        {
            var fooUserTasks = new UserTasks();

            fooUserTasks.Id                = userTaskVM.Id;
            fooUserTasks.Account           = userTaskVM.Account;
            fooUserTasks.CheckinDatetime   = userTaskVM.CheckinDatetime;
            fooUserTasks.CheckinId         = userTaskVM.CheckinId;
            fooUserTasks.Checkin_Latitude  = userTaskVM.Checkin_Latitude;
            fooUserTasks.Checkin_Longitude = userTaskVM.Checkin_Longitude;
            fooUserTasks.Condition1_Ttile  = userTaskVM.Condition1_Ttile;
            fooUserTasks.Condition1_Result = userTaskVM.Condition1_Result;
            fooUserTasks.Condition2_Ttile  = userTaskVM.Condition2_Ttile;
            fooUserTasks.Condition2_Result = userTaskVM.Condition2_Result;
            fooUserTasks.Condition3_Ttile  = userTaskVM.Condition3_Ttile;
            fooUserTasks.Condition3_Result = userTaskVM.Condition3_Result;
            fooUserTasks.Description       = userTaskVM.Description;
            fooUserTasks.PhotoURL          = userTaskVM.PhotoURL;
            fooUserTasks.Reported          = userTaskVM.Reported;
            fooUserTasks.ReportedDatetime  = userTaskVM.ReportedDatetime;
            fooUserTasks.Status            = userTaskVM.Status;
            fooUserTasks.TaskDateTime      = userTaskVM.TaskDateTime;
            fooUserTasks.Title             = userTaskVM.Title;
            return(fooUserTasks);
        }
示例#8
0
        public IActionResult AddTask(UserTasks t)
        {
            int result = dal.CreateTask(t);


            return(RedirectToAction("Index"));
        }
 /// <summary>
 /// 使用者已經填寫工作內容了,將狀態更新到資料已經輸入狀態
 /// </summary>
 /// <param name="userTasks">App傳入的工作紀錄</param>
 /// <param name="targetDB">要更新到資料庫內的工作紀錄</param>
 private void UpdateStatus_INPUT(UserTasks userTasks, UserTasks targetDB)
 {
     targetDB.Status            = TaskStatus.INPUT;
     targetDB.Condition1_Result = userTasks.Condition1_Result;
     targetDB.Condition2_Result = userTasks.Condition2_Result;
     targetDB.Condition3_Result = userTasks.Condition3_Result;
 }
示例#10
0
        public async Task <IActionResult> PutUserTasks([FromRoute] int id, [FromBody] UserTasks userTasks)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userTasks.Id)
            {
                return(BadRequest());
            }

            _context.Entry(userTasks).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserTasksExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 /// <summary>
 /// 使用者已經打卡了,將狀態更新到打卡狀態
 /// </summary>
 /// <param name="source"></param>
 /// <param name="targetDB"></param>
 void UpdateStatus_CHECKIN(UserTasks source, UserTasks targetDB)
 {
     targetDB.Status            = TaskStatus.CHECKIN;
     targetDB.CheckinDatetime   = DateTime.UtcNow.AddHours(8);
     targetDB.Checkin_Latitude  = source.Checkin_Latitude;
     targetDB.Checkin_Longitude = source.Checkin_Longitude;
 }
示例#12
0
 public void AddTask(TaskInfo task)
 {
     for (int i = 0; i < m_Users.Count; i++)
     {
         if (m_Users[i].Id == task.IspId)
         {
             if (m_UserTasksList.Count == 0)
             {
                 UserTasks ut = new UserTasks(m_Users[i]);
                 ut.Tasks.Add(task.Copy());
                 m_UserTasksList.Add(ut);
             }
             else
             {
                 bool have_task = false;
                 for (int j = 0; j < m_UserTasksList.Count; j++)
                 {
                     if (m_UserTasksList[j].User.Id == task.IspId)
                     {
                         m_UserTasksList[j].Tasks.Add(task);
                         have_task = true;
                         break;
                     }
                 }
                 if (!have_task)
                 {
                     UserTasks ut = new UserTasks(m_Users[i]);
                     ut.Tasks.Add(task);
                     m_UserTasksList.Add(ut);
                     break;
                 }
             }
         }
     }
 }
示例#13
0
        void AddViewModel(UserTasks userTask)
        {
            UserTasksVM fooUserTasksVM = new UserTasksVM
            {
                Account           = userTask.Account,
                CheckinDatetime   = userTask.CheckinDatetime,
                CheckinId         = userTask.CheckinId,
                Checkin_Latitude  = userTask.Checkin_Latitude,
                Checkin_Longitude = userTask.Checkin_Longitude,
                Condition1_Result = userTask.Condition1_Result,
                Condition1_Ttile  = userTask.Condition1_Ttile,
                Condition2_Result = userTask.Condition2_Result,
                Condition2_Ttile  = userTask.Condition2_Ttile,
                Condition3_Result = userTask.Condition3_Result,
                Condition3_Ttile  = userTask.Condition3_Ttile,
                Description       = userTask.Description,
                Id               = userTask.Id,
                PhotoURL         = userTask.PhotoURL,
                Reported         = userTask.Reported,
                ReportedDatetime = userTask.ReportedDatetime,
                Status           = userTask.Status,
                TaskDateTime     = userTask.TaskDateTime,
                Title            = userTask.Title,
            };

            UserTasksList.Add(fooUserTasksVM);
        }
示例#14
0
        public async Task <IActionResult> Create(UserTasks taskModel)
        {
            if (taskModel == null)
            {
                return(View(taskModel));
            }
            var task = new UserTasks();

            task.Name = taskModel.Name;
            await _dcreatetask.Create(task);



            var Email  = _httpContextAccessor.HttpContext.User.Identity.Name;
            var UserId = await _dGetByEmail.UserByEmail(Email);

            var modal = new Activitydata();

            modal.FullName = UserId.FullName;
            modal.Name     = taskModel.Name;
            modal.UserId   = UserId.Id;
            modal.Status   = "Created by";
            await _daddtaskactivity.Create(modal);

            TempData["Sucess"] = "Task has been added";
            return(RedirectToAction("Create", "Task"));
        }
示例#15
0
        public void TestDeactivateUser()
        {
            IConfiguration config = getTestConfiguration();

            using (var context = new SGContext(config))
            {
                var token = quickLogin(context, "admin@localhost", "password");
                Assert.IsTrue(token != null, "Unable to log in as admin user.  Test can't run");

                var testUser  = TryCreateUser(context, token, "deactiveUser@localhost", "password2");
                var userToken = quickLogin(context, "deactiveUser@localhost", "password2");
                Assert.IsTrue(userToken != null, "Unable to log in as activation test user.  Test can't run");

                UserTasks.SetUserActiveAsync(context, token, "deactiveUser@localhost", false).Wait();

                var task = LoginTokenTasks.GetLoginTokenAsync(context, userToken.Id);
                task.Wait();
                var userToken2 = task.Result;
                Assert.IsNull(userToken2, "A user's tokens should not be available after deactivation.");

                userToken = quickLogin(context, "deactiveUser@localhost", "password2");
                Assert.IsNull(userToken2, "A user's should not be able to login after deactivation.");

                UserTasks.SetUserActiveAsync(context, token, "deactiveUser@localhost", true).Wait();

                task = LoginTokenTasks.GetLoginTokenAsync(context, userToken.Id);
                task.Wait();
                var userToken3 = task.Result;
                Assert.IsNotNull(userToken3, "User failed to login after reactivation.");
            }
        }
        public ActionResult Create(CreateFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Statuses = _context.Statuses.ToList();
                return(View("Create", viewModel));
            }

            var status = _context.Statuses.Single(t => t.Id == viewModel.Status);

            DateTime.TryParseExact(viewModel.Date,
                                   "dd MMM yyyy",
                                   CultureInfo.CurrentCulture,
                                   DateTimeStyles.None,
                                   out DateTime dateTime);

            var project = new Project
            {
                UserId         = User.Identity.GetUserId(),
                ProjectTitle   = viewModel.ProjectTitle,
                ProjectDetails = viewModel.ProjectDetails,
                DateTime       = dateTime,
                Status         = status,
            };

            //project.Tasks.Add(new Task());

            _context.Project.Add(project);
            _context.SaveChanges();

            string[] tasks   = viewModel.Task.Split(',');
            var      AppUser = _context.Users.FirstOrDefault(u => u.Email == User.Identity.Name);

            foreach (var tsk in tasks)
            {
                string[] tskDetails = tsk.Split(':');

                ProjectTask newTask = new ProjectTask
                {
                    TaskTitle   = tskDetails[0],
                    TaskHandler = tskDetails[1]
                };

                //newTask.Users.Add(AppUser);
                _context.Tasks.Add(newTask);
                project.Tasks.Add(newTask);
                _context.SaveChanges();

                UserTasks userTask = new UserTasks
                {
                    UserId = AppUser.Id,
                    TaskId = newTask.Id
                };
                _context.UsersTasks.Add(userTask);
                _context.SaveChanges();
            }

            return(RedirectToAction("Index", "Home"));
        }
示例#17
0
        public IActionResult SortByDateDesc(UserTasks t)
        {
            IEnumerable <UserTasks> results = dal.SortByDateDesc(t);

            ViewData["Tasks"] = results;

            return(View("../Task/Index"));
        }
示例#18
0
 public async Task Create(UserTasks task)
 {
     List <SQLParam> sQLParams = new List <SQLParam>()
     {
         new SQLParam("@name", task.Name)
     };
     await _createtask.Create(sQLParams);
 }
示例#19
0
        public ActionResult DeleteConfirmed(long id)
        {
            UserTasks userTasks = db.UserTasks.Find(id);

            db.UserTasks.Remove(userTasks);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult TaskNew(UserTasks userTaskdto)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(userTaskdto.Name))
                    {
                        throw new Exception("Enter task name");
                    }

                    if (string.IsNullOrEmpty(userTaskdto.Description))
                    {
                        throw new Exception("Enter task description");
                    }

                    bool isUserExist = DAL.Db().Fetch <ApplicationUsers>(" where id=@0", userTaskdto.AssignedBy).Any();

                    if (!isUserExist)
                    {
                        throw new Exception("Invalid assigned by user found !!");
                    }

                    isUserExist = DAL.Db().Fetch <ApplicationUsers>(" where id=@0", userTaskdto.AssignedTo).Any();

                    if (!isUserExist)
                    {
                        throw new Exception("Invalid assigned to user found !!");
                    }

                    if (userTaskdto.ToDate < userTaskdto.FromDate)
                    {
                        throw new Exception("To date should be greater than from date");
                    }


                    DAL.Db().Save(userTaskdto);

                    TempData["ModelSuccess"] = "Task successfully saved";

                    userTaskdto = new UserTasks();
                    ModelState.Clear();
                }
                else
                {
                    throw new Exception("some errors found.");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            ViewBag.Users = DAL.Db().Query <ApplicationUsers>("select Id,Name from ApplicationUsers");
            ViewBag.Tasks = DAL.Db().Query <UserTasks>("select Id,Name from UserTasks");

            return(View(userTaskdto));
        }
        public void AddNumbersShouldAddTwoNumbers()
        {
            var       userTasks        = new UserTasks();
            const int firstNumber      = 2;
            const int secondNumber     = 4;
            var       addNumbersResult = userTasks.AddNumbers(firstNumber, secondNumber);

            Assert.AreEqual(addNumbersResult, 6);
        }
示例#22
0
        public async Task <ActionResult> DeleteConfirmed(long id)
        {
            UserTasks userTasks = await db.UserTasks.FindAsync(id);

            db.UserTasks.Remove(userTasks);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
示例#23
0
 public async Task Update(UserTasks task)
 {
     List <SQLParam> sQLParams = new List <SQLParam>()
     {
         new SQLParam("@id", task.Id),
         new SQLParam("@name", task.Name)
     };
     await _edittask.Update(sQLParams);
 }
        public void MultiplyNumbersShouldMultiplyNumbers()
        {
            var userTask              = new UserTasks();
            int firstNumber           = 2;
            int secondNumber          = 4;
            var multiplyNumbersResult = userTask.MultiplyNumbers(firstNumber, secondNumber);

            Assert.AreEqual(multiplyNumbersResult, 8);
        }
示例#25
0
        /// <summary>
        /// Adds a task based on user input.
        /// </summary>
        /// <param name="task">The task.</param>
        public void AddUserTask(string task)
        {
            if (string.IsNullOrEmpty(task))
            {
                return;
            }

            UserTasks.Add(task);
        }
示例#26
0
 public ActionResult Edit([Bind(Include = "TaskId,Tittle,UserID,DateCreation,DateDue")] UserTasks userTasks)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userTasks).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userTasks));
 }
示例#27
0
 public ActionResult Edit([Bind(Include = "TaskId,Title,UserName,InitialDate,EndDate,Message,UserId")] UserTasks userTasks)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userTasks).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userTasks));
 }
示例#28
0
        public IActionResult EditTask(int id)
        {
            UserTasks foundTask = _context.UserTasks.Find(id);

            if (foundTask != null)
            {
                return(View(foundTask));
            }
            return(View());
        }
示例#29
0
        public APIResult Get()
        {
            var fooToday = DateTime.Now.Date;
            // 查詢今天產生的工作有那些
            var fooTasks = db.UserTasks.Where(x => DbFunctions.TruncateTime(x.TaskDateTime) == fooToday).ToList();

            if (fooTasks.Count > 0)
            {
                #region 今天的工作已經有產生了
                fooAPIResult.Success = false;
                fooAPIResult.Message = DateTime.Now.ToString("yyyy.MM.dd") + " 已經有存在的的代辦工作";
                fooAPIResult.Payload = null;
                #endregion
            }
            else
            {
                #region 幫每個使用者,產生今天要用到的五個工作
                for (int i = 0; i < 40; i++)
                {
                    var fooAccount = $"user{i}";
                    for (int j = 0; j < 5; j++)
                    {
                        var fooTask = new UserTasks()
                        {
                            Account           = fooAccount,
                            Title             = $"請前往地點 {j} 進行簽到與調查作業環境",
                            Description       = "請到指定地點掃描 QR Code,並且填寫當時工作環境數據",
                            TaskDateTime      = DateTime.Now.Date,
                            CheckinId         = RandomString(30),
                            Condition1_Ttile  = "請讀取儀表1的數據",
                            Condition1_Result = "",
                            Condition2_Ttile  = "請讀取儀表2的數據",
                            Condition2_Result = "",
                            Condition3_Ttile  = "請讀取儀表3的數據",
                            Condition3_Result = "",
                            Checkin_Latitude  = 0,
                            Checkin_Longitude = 0,
                            PhotoURL          = "",
                            Reported          = false,
                            ReportedDatetime  = new DateTime(1900, 1, 1),
                            CheckinDatetime   = new DateTime(1900, 1, 1),
                        };

                        db.UserTasks.Add(fooTask);
                    }
                }
                #endregion
                db.SaveChanges();

                fooAPIResult.Success = true;
                fooAPIResult.Message = DateTime.Now.ToString("yyyy.MM.dd") + " 的代辦工作已經產生完成";
                fooAPIResult.Payload = null;
            }
            return(fooAPIResult);
        }
示例#30
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Account,TaskDateTime,Status,Title,Description,CheckinId,Checkin_Latitude,Checkin_Longitude,CheckinDatetime,Condition1_Ttile,Condition1_Result,Condition2_Ttile,Condition2_Result,Condition3_Ttile,Condition3_Result,PhotoURL,Reported,ReportedDatetime")] UserTasks userTasks)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userTasks).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(userTasks));
        }
示例#31
0
文件: Start.cs 项目: DingyClot/Tymrr
 public void Initialise()
 {
     app = new AppUnderTest(ui);
     user = app.UserTasks;
 }