Exemplo n.º 1
0
 public ActionResult Create(int classroomId, string returnUrl)
 {
     try
     {
         ViewBag.returnUrl = returnUrl;
         var newTask = new NewTaskModel()
         {
             ClassroomId = classroomId
         };
         return(View(newTask));
     }
     catch (Exception e)
     {
         return(RedirectToAction("Index", "Error", new { error = e.Message }));
     }
 }
Exemplo n.º 2
0
        public static void Create(NewTaskModel task)
        {
            var  db     = IsYonetim.DataBase;
            Task dbTask = new Task
            {
                Title        = task.Title,
                Text         = task.Text,
                BeginTime    = DateTime.Now,
                EndTime      = task.EndTime,
                State        = task.State,
                ParentTaskId = task.ParentId,
            };

            db.Tasks.Add(dbTask);
            db.SaveChanges();
        }
Exemplo n.º 3
0
        private void _view_CreateTaskButtonClicked(object sender, EventArgs e)
        {
            INewTaskModel    model     = new NewTaskModel();
            NewTaskView      view      = new NewTaskView();
            NewTaskPresenter presenter = new NewTaskPresenter(model, view);

            DialogResult result = view.ShowDialog();

            if (result != DialogResult.None)
            {
                if (result == DialogResult.OK)
                {
                    _model.AddTask(model.NewTask);
                }

                view.Close();
            }
        }
Exemplo n.º 4
0
 public IActionResult AddNewTask(NewTaskModel newTaskModel)
 {
     try
     {
         Task task = new Task()
         {
             Date   = DateTime.Now,
             Text   = newTaskModel.TaskText,
             UserId = newTaskModel.UserId
         };
         db.Tasks.Add(task);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(RedirectToAction("Error404"));
     }
 }
Exemplo n.º 5
0
 public ActionResult Create(NewTaskModel model, string returnUrl)
 {
     try
     {
         var taskCreator = db.Users.Find(User.Identity.GetUserId());
         if (taskCreator != null)
         {
             var classroom = db.Classrooms.Include(x => x.Tasks).FirstOrDefault(x => model.ClassroomId == x.Id);
             if (classroom != null)
             {
                 classroom.Tasks.Add(new Task()
                 {
                     Title       = model.Title,
                     Content     = model.Content,
                     TaskCreator = taskCreator
                 });
                 db.SaveChanges();
                 if (string.IsNullOrEmpty(returnUrl))
                 {
                     return(RedirectToAction("Index"));
                 }
                 return(Redirect(returnUrl));
             }
             else
             {
                 ModelState.AddModelError("", "Такого класса не существует!");
                 return(View(model));
             }
         }
         else
         {
             ModelState.AddModelError("", "Пользователя не существует!");
             return(View());
         }
     }
     catch (Exception e)
     {
         return(RedirectToAction("Index", "Error", new { error = e.Message }));
     }
 }
Exemplo n.º 6
0
        public async Task <JsonResult> AddNewTask(NewTaskModel model)
        {
            var result = new ApiJsonResult();

            try
            {
                using (var dbContext = new DatabaseContext())
                {
                    var user = dbContext.Users.FirstOrDefault(x => x.ApiKey == model.ApiKey);
                    if (user == null)
                    {
                        result.IsSuccess = false;
                        result.Message   = "The key value is wrong";
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(model.Name))
                        {
                            result.IsSuccess = false;
                            result.Message   = "The name value is required";
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(model.Network))
                            {
                                result.IsSuccess = false;
                                result.Message   = "The network value is required";
                            }
                            else
                            {
                                if (model.Network != "testnet-r4_2" && model.Network != "DevsDappsTestnet" && model.Network != "CreditsNetwork")
                                {
                                    result.IsSuccess = false;
                                    result.Message   = "The network value is wrong. Supported values: 'testnet-r4_2', 'DevsDappsTestnet', 'CreditsNetwork'";
                                }
                                else
                                {
                                    if (string.IsNullOrEmpty(model.Method))
                                    {
                                        result.IsSuccess = false;
                                        result.Message   = "The method value is required";
                                    }
                                    else
                                    {
                                        if (string.IsNullOrEmpty(model.Address))
                                        {
                                            result.IsSuccess = false;
                                            result.Message   = "The address value is required";
                                        }
                                        else
                                        {
                                            if (string.IsNullOrEmpty(model.ExecutionMode))
                                            {
                                                result.IsSuccess = false;
                                                result.Message   = "The executionMode value is required";
                                            }
                                            else
                                            {
                                                if (model.ExecutionMode == "Regular")
                                                {
                                                    if (CheckDate(model.RegularDateFrom) == DateTime.MinValue)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularDateFrom value is wrong. Supported mask: mm-DD-YYYY-hh-MM-ss";
                                                    }
                                                    else if (CheckDate(model.RegularDateTo) == DateTime.MinValue)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularDateTo value is wrong. Supported mask: mm-DD-YYYY-hh-MM-ss";
                                                    }
                                                    else if (CheckPeriodName(model.RegularPeriod) == 0)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularPeriod value is wrong. Supported values: 'Minutes', 'Hours', 'Days'";
                                                    }
                                                    else if (CheckPeriodValue(model.RegularValue) == 0)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularValue value is wrong. Supported values: 1, 2, 3, and so on...";
                                                    }
                                                }
                                                else if (model.ExecutionMode == "Once")
                                                {
                                                    if (CheckDate(model.OnceDate) == DateTime.MinValue)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The onceDate value is wrong. Supported mask: mm-DD-YYYY-hh-MM-ss";
                                                    }
                                                }
                                                else if (model.ExecutionMode == "InSeconds")
                                                {
                                                    if (CheckInSeconds(model.InSecondsValue) == false)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The InSecondsValue value is wrong. Value must be integer value";
                                                    }
                                                    else
                                                    {
                                                        var seconds       = Convert.ToInt32(model.InSecondsValue);
                                                        var dateExecution = DateTime.Now.AddSeconds(seconds);
                                                        model.OnceDate = dateExecution.ToString("MM-dd-yyyy-HH-mm-ss");
                                                    }
                                                }
                                                else if (model.ExecutionMode == "CronExpression")
                                                {
                                                }
                                                else
                                                {
                                                    result.IsSuccess = false;
                                                    result.Message   = "The executionMode value is wrong. Supported values: 'Regular', 'Once', 'CronExpression'";
                                                }

                                                //Ошибок нет, создаем новую задачу
                                                if (!result.IsSuccess)
                                                {
                                                    var smartJob = new SmartJob();
                                                    smartJob           = new SmartJob();
                                                    smartJob.CreatedBy = user;
                                                    smartJob.CreatedAt = DateTime.Now;
                                                    smartJob.Rule      = new Rule();
                                                    smartJob.Events    = new List <JobEvent>();
                                                    smartJob.Name      = model.Name;
                                                    smartJob.IsActive  = true;
                                                    smartJob.Method    = model.Method;
                                                    smartJob.Address   = model.Address;
                                                    smartJob.IsDeleted = false;
                                                    smartJob.DeleteTaskAfterExecution = model.DeleteTaskAfterExecution == "1";
                                                    smartJob.CreditsNet           = dbContext.CreditsNets.FirstOrDefault(x => x.Name == model.Network);
                                                    smartJob.ExecutionMode        = CheckExecutionMode(model.ExecutionMode);
                                                    smartJob.Rule.RegularDateFrom = CheckDate(model.RegularDateFrom).ToString("MM/dd/yyyy HH:mm:ss");
                                                    smartJob.Rule.RegularDateTo   = CheckDate(model.RegularDateTo).ToString("MM/dd/yyyy HH:mm:ss");
                                                    smartJob.Rule.RegularPeriod   = ConvertPeriod(model.RegularPeriod);
                                                    smartJob.Rule.RegularValue    = CheckPeriodValue(model.RegularValue);
                                                    smartJob.Rule.OnceDate        = CheckDate(model.OnceDate).ToString("MM/dd/yyyy HH:mm:ss");
                                                    smartJob.Rule.CronExpression  = model.CronExpression;
                                                    smartJob.Rule.Presentation    = Rule.GeneratePresentation(smartJob);

                                                    dbContext.SmartJobs.Add(smartJob);
                                                    await dbContext.SaveChangesAsync();

                                                    //Обновляем данные по задаче
                                                    await QuartzTasks.UpdateJob(smartJob.ID);

                                                    result.IsSuccess = true;
                                                    result.Message   = "Action completed";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (DbEntityValidationException err)
            {
                var outputLines = new List <string>();

                foreach (var eve in err.EntityValidationErrors)
                {
                    outputLines.Add(
                        $"{DateTime.Now}: Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:");
                    outputLines.AddRange(eve.ValidationErrors.Select(ve =>
                                                                     $"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""));
                }

                result.IsSuccess = false;
                result.Message   = String.Join(", ", outputLines.ToArray());
            }
            catch (Exception err)
            {
                result.IsSuccess = false;
                result.Message   = err.ToString();
            }

            return(new JsonResult
            {
                MaxJsonLength = Int32.MaxValue,
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemplo n.º 7
0
 public IActionResult Post([FromBody] NewTaskModel model)
 {
     _taskService.Create(model);
     return(Ok(MessageHelper.Success("The task has been created successfully.")));
 }
Exemplo n.º 8
0
        public void Create(NewTaskModel model)
        {
            var taskOwner =
                _systemUserRepository.GetFirstOrDefault(predicate: a => a.SystemUserId == model.FromSystemUserId,
                                                        include: a => a.Include(b => b.Business).ThenInclude(c => c.BusinessToBusiness));

            var taskReceiver =
                _systemUserRepository.GetFirstOrDefault(predicate: a => a.SystemUserId == model.ToSystemUserId,
                                                        include: a => a.Include(b => b.Business));

            var assigneeSystemUser =
                model.AssignedToSystemUserId.HasValue
                    ? _systemUserRepository.GetFirstOrDefault(
                    predicate: a => a.SystemUserId == model.AssignedToSystemUserId,
                    include: a => a.Include(b => b.Business))
                    : null;

            ValidateAssigning(taskOwner, taskReceiver);

            var mentor       = taskOwner.Business.EduBusinessType == (int)EduBusinessType.Mentor ? taskOwner : taskReceiver;
            var mentee       = taskOwner.Business.EduBusinessType == (int)EduBusinessType.Mentee ? taskOwner : taskReceiver;
            var channelTask  = GetChannelTask(mentor.BusinessId, mentee.BusinessId);
            var lastSequence = channelTask != null
                ? _taskRepository.GetFirstOrDefault(predicate : a => a.MentifiTaskId == channelTask.MentifiChannelTaskId,
                                                    orderBy : a => a.OrderByDescending(b => b.Sequence))?.Sequence ?? 0
                : 0;

            var task = new MentifiTask()
            {
                CreatedOn            = DateTime.UtcNow,
                CreatedBy            = taskOwner.BusinessId,
                Status               = model.Status,
                Priority             = model.Priority,
                AssignedTo           = assigneeSystemUser?.BusinessId,
                DueDate              = model.DueDate.FromUnixTime(),
                TaskSubject          = model.Subject,
                Sequence             = lastSequence,
                MentifiChannelTaskId = channelTask?.MentifiChannelTaskId ?? 0
            };

            if (channelTask == null)
            {
                task.MentifiChannelTask = new MentifiChannelTask()
                {
                    MenteeId = mentee.BusinessId,
                    MentorId = mentor.BusinessId
                };
            }
            _taskRepository.Insert(task);

            CreateNotif(taskOwner, Constant.MentifiNotification.TASK_CREATED, taskReceiver.SystemUserId);

            if (model.AssignedToSystemUserId.HasValue && model.AssignedToSystemUserId > 0)
            {
                CreateNotif(taskOwner, Constant.MentifiNotification.TASK_ASSIGNED, model.AssignedToSystemUserId.Value);
            }

            if (model.Status == MentifiTaskStatus.Completed)
            {
                CreateNotif(taskOwner, Constant.MentifiNotification.TASK_COMPLETED, taskReceiver.SystemUserId);
            }

            _unitOfWork.SaveChanges();
        }