Example #1
0
        public RequestResponse CreateTask(TaskCreate model)
        {
            if (model == null)
            {
                return(BadResponse("Request Body was empty."));
            }

            var userMembership = GetUserMembership(model.GroupId);

            if (userMembership == null || !userMembership.IsOfficer)
            {
                return(BadResponse("Invalid permissions."));
            }

            var taskEntity = new TaskEntity
            {
                GroupId     = model.GroupId,
                TaskName    = model.TaskName,
                Description = model.Description,
                RewardValue = model.RewardValue,
                CreatedUtc  = DateTimeOffset.Now
            };

            _context.Tasks.Add(taskEntity);

            if (_context.SaveChanges() != 1)
            {
                return(BadResponse("Cannot save new task."));
            }

            return(OkResponse("Task created successfully."));
        }
Example #2
0
        public ActionResult EditTask(int TaskID, string TaskName, string AssignerName, string AssigneeName, string AssignedDate, string DueDate, string StatusName, string PriorityName)
        {
            TaskCreate taskCreate = new TaskCreate();

            taskCreate.TaskID           = TaskID;
            taskCreate.TaskName         = TaskName;
            taskCreate.SelectedAssigner = AssignerName;
            taskCreate.SelectedAssignee = AssigneeName;
            taskCreate.AssignedDate     = Convert.ToDateTime(AssignedDate);
            taskCreate.DueDate          = Convert.ToDateTime(DueDate);
            taskCreate.SelectedStatus   = StatusName;
            taskCreate.SelectedPriority = PriorityName;
            httpClient.BaseAddress      = new Uri("http://localhost:49982");
            httpClient.DefaultRequestHeaders.Accept.
            Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            result = httpClient.PostAsJsonAsync("api/Tasks/EditTask", taskCreate).
                     Result.Content.ReadAsStringAsync().Result;

            if (result == "\"success\"")
            {
                return(RedirectToAction("TaskList", "Task"));
            }

            else
            {
                return(View(""));
            }
        }
Example #3
0
        public IActionResult Create([FromBody] TaskCreate taskCreate)
        {
            var viewModel = new ClassModel();

            if (ModelState.IsValid)
            {
                var taskTickets = new TaskTickets
                {
                    //Created = true,
                    //StatusId = 0,
                    CategoryId = taskCreate.CategoryId,
                    SiteID     = taskCreate.SiteID,
                    SeverityId = taskCreate.SeverityId
                };
                _context.Add(taskTickets);

                foreach (TaskProjectList item in taskCreate.TaskProjectList)
                {
                    item.TicketId = taskTickets.TicketId;

                    _context.TaskProjectList.Add(item);
                }

                int save = _context.SaveChanges();

                return(View(save));
            }
            //ViewData["SiteID"] = new SelectList(_context.AdmSite, "SiteID", "Sitename");
            //ViewData["CategoryId"] = new SelectList(_context.TaskCategory, "CategoryId", "CategoryName");
            //ViewData["SeverityId"] = new SelectList(_context.TaskSeverity, "SeverityId", "SeverityName");
            viewModel.ProjectList = _context.TaskProjectList.ToList();
            return(View(viewModel));
        }
Example #4
0
        // GET: Tasks/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProjectTask projectTask = db.ProjectTasks
                                      .Where(t => t.TaskID == id.Value)
                                      .Include(t => t.Users)
                                      .Include(t => t.Attachments)
                                      .FirstOrDefault();

            if (projectTask.OwnerID != User.Identity.GetUserId())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (projectTask == null)
            {
                return(HttpNotFound());
            }
            TaskCreate viewModel = new TaskCreate()
            {
                Deadline        = projectTask.Deadline.ToUnixTimestamp(),
                Users           = projectTask.Users,
                TaskID          = projectTask.TaskID,
                Description     = projectTask.Description,
                Name            = projectTask.Name,
                ParentProjectID = projectTask.ParentProjectID
            };

            this.prepareCreateViewModel(viewModel);
            return(View("Create", viewModel));
        }
Example #5
0
        // GET: Tasks/Create
        public ActionResult Create()
        {
            TaskCreate viewModel = new TaskCreate();

            // Load projects where the user has management rights
            this.prepareCreateViewModel(viewModel);
            return(View(viewModel));
        }
Example #6
0
        public async Task <TaskView> Create(CancellationToken cancellationToken, [FromBody] TaskCreate data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            using var mgr = new Manager(_emi);
            return(await mgr.Creator.Create(data, cancellationToken));
        }
Example #7
0
        public IHttpActionResult CreateNewTask(TaskCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service        = GetTaskService();
            var createResponse = service.CreateTask(model);

            return(ValidateRequestResponse(createResponse));
        }
Example #8
0
        private TaskCreate getCreateViewModel(TaskCreateDTO dto)
        {
            TaskCreate viewModel = new TaskCreate();

            viewModel.TaskID          = dto.TaskID;
            viewModel.Name            = dto.Name;
            viewModel.ParentProjectID = dto.ParentProjectID;
            viewModel.Description     = dto.Description;
            viewModel.Deadline        = dto.Deadline;
            viewModel.Users           = dto.Users;
            viewModel.Files           = dto.Files;
            return(viewModel);
        }
Example #9
0
        public async Task <TaskView> Create(TaskCreate data, CancellationToken cancellationToken = default)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var oData = data.CopyPropertiesToNewObject <Models.Task>();

            oData.CreatedAt = DateTime.Now;
            await _manager.DbContext.AddAsync(oData, cancellationToken);

            await _manager.DbContext.SaveChangesAsync(cancellationToken);

            return(oData.CastToView());
        }
Example #10
0
        public ActionResult AddNewTask(TaskCreate taskCreate)
        {
            httpClient.BaseAddress = new Uri("http://localhost:49982");
            httpClient.DefaultRequestHeaders.Accept.
            Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            result = httpClient.PostAsJsonAsync("api/Tasks/AddNewTask", taskCreate).
                     Result.Content.ReadAsStringAsync().Result;

            if (result == "\"success\"")
            {
                return(RedirectToAction("TaskList", "Task"));
            }

            else
            {
                return(View(""));
            }
        }
Example #11
0
        public bool CreateTask(TaskCreate model)
        {
            var entity =
                new Taskl()
            {
                TaskOwnerId = _userId,
                TaskName    = model.TaskName,
                TaskSummary = model.TaskSummary,
                DueDate     = model.DueDate,
                Flagged     = model.Flagged,
                Completed   = model.Completed,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Tasks.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #12
0
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <TASK>
            <NAME>hello world</NAME>
            <PROJECTID>P1234</PROJECTID>
        </TASK>
    </create>
</function>";

            TaskCreate record = new TaskCreate("unittest")
            {
                TaskName  = "hello world",
                ProjectId = "P1234"
            };

            this.CompareXml(expected, record);
        }
Example #13
0
        public ActionResult Create(TaskCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateTaskService();

            if (service.CreateTask(model))
            {
                TempData["SaveResult"] = "Your task was created!";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "The task could not be created!");

            return(View(model));
        }
Example #14
0
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <TASK>
            <NAME>hello world</NAME>
            <PROJECTID>P1234</PROJECTID>
        </TASK>
    </create>
</function>";

            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Encoding    = Encoding.UTF8;
            xmlSettings.Indent      = true;
            xmlSettings.IndentChars = "    ";

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            TaskCreate record = new TaskCreate("unittest");

            record.TaskName  = "hello world";
            record.ProjectId = "P1234";

            record.WriteXml(ref xml);

            xml.Flush();
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);

            Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd())
                           .WithDifferenceEvaluator(DifferenceEvaluators.Default)
                           .Build();

            Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString());
        }
Example #15
0
        private void prepareCreateViewModel(TaskCreate viewModel, string userID = null)
        {
            if (userID == null)
            {
                userID = User.Identity.GetUserId();
            }
            viewModel.SelectableProjects = db.ProjectRoles
                                           .Where(r => r.UserID == userID && r.Role < Role.Worker)
                                           .Include(r => r.Project)
                                           .ToList()
                                           .Select(r => new KeyValuePair <object, string>(r.ProjectID, r.Project.Name))
                                           .ToList();
            int projectID = viewModel.ParentProjectID == 0? (int)viewModel.SelectableProjects.First().Key : viewModel.ParentProjectID;

            viewModel.SelectableUsers = this.db.Projects
                                        .Where(x => x.ProjectID == projectID)
                                        .Include(x => x.Roles.Select(r => r.User))
                                        .First()
                                        .Roles
                                        .Select(r => new KeyValuePair <object, string>(r.User.Id, r.User.Email))
                                        .ToList();
            viewModel.SelectableUsers.Insert(0, new KeyValuePair <object, string>(null, null));
        }
Example #16
0
 public ActionResult NewTask(TaskCreate taskCreate)
 {
     return(View());
 }
Example #17
0
        public ActionResult Create(TaskCreateDTO form)
        {
            form?.Users.RemoveAll(u => u.Id == null);
            if (ModelState.IsValid)
            {
                ProjectTask task;
                if (form.TaskID != 0)
                {
                    task = this.db.ProjectTasks
                           .Where(x => x.TaskID == form.TaskID)
                           .Include(x => x.Users)
                           .FirstOrDefault();
                    if (task.OwnerID != User.Identity.GetUserId())
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }

                    // remove users that are no longer assigned to the task
                    task.Users.RemoveAll(x => !form.Users.Contains(x, new PropertyComparer <ApplicationUser, string>(u => u.Id)));
                    // remove duplicates
                    form.Users.RemoveAll(x => task.Users.Contains(x, new PropertyComparer <ApplicationUser, string>(u => u.Id)));
                }
                else
                {
                    // if not project manager nor owner => task addition refused
                    if ((!this.db.HasProjectRole(form.ParentProjectID, User.Identity.GetUserId(), Role.Manager)))
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }
                    task         = new ProjectTask();
                    task.Created = DateTime.UtcNow;
                }
                // task not found
                if (task == null)
                {
                    return(HttpNotFound());
                }
                if (task.Users == null)
                {
                    task.Users = new List <ApplicationUser>();
                }
                task.LastModified    = DateTime.UtcNow;
                task.Deadline        = UnixTime.ParseUnixTimestamp(form.Deadline);
                task.Description     = form.Description;
                task.Name            = form.Name;
                task.OwnerID         = User.Identity.GetUserId();
                task.ParentProjectID = form.ParentProjectID;
                task.Status          = form.Users.Count() > 0 ? TaskStatus.Assigned : TaskStatus.Created;
                form.Users.ForEach(u => this.db.Users.Attach(u));
                form.Users.ForEach(x => task.Users.Add(x));
                List <Attachment> attachments = new List <Attachment>();
                if (task.TaskID == 0)
                {
                    db.ProjectTasks.Add(task);
                }
                db.SaveChanges();

                // save all attachments
                foreach (var val in form.Files)
                {
                    if (val != null)
                    {
                        db.Attachments.Add(new Attachment()
                        {
                            FileName = val.FileName, Size = val.ContentLength, Type = val.ContentType, TaskID = task.TaskID
                        });
                        DirectoryInfo dir = Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"Attachments/" + task.TaskID);
                        val.SaveAs(dir.FullName + @"/" + val.FileName);
                    }
                }

                db.SaveChanges();
                return(this.Redirect("/Projects/Details/" + form.ParentProjectID));
            }
            else
            {
                TaskCreate viewModel = this.getCreateViewModel(form);
                this.prepareCreateViewModel(viewModel);
                return(View(viewModel));
            }
        }
 public async Task<TaskCreate.response> TaskCreate(TaskCreate.request request, CancellationToken? token = null)
 {
     return await SendAsync<TaskCreate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
Example #19
0
        public void Execute(string input)
        {
            var request = new TaskCreate();

            request.Execute(input);
        }