Ejemplo n.º 1
0
        public IActionResult Create(TaskCreateInputModel model)
        {
            if (!DataValidator.ValidateObject(model))
            {
                //TODO: return Error;
            }

            this.tasksService.CreateTask(model);

            return(this.RedirectToAction("/"));
        }
        public async Task <IActionResult> Create(TaskCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var traineeId = await this.taskService.Create(model);

            var controller = ControllerHelper.GetControllerName(nameof(TraineesController));

            return(this.RedirectToAction(nameof(TraineesController.Details), controller, new { id = traineeId }));
        }
        public IActionResult Create(TaskCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Tasks/Create"));
            }

            if (model.AffectedSectors.Count == 0)
            {
                ModelState.Add(nameof(model.AffectedSectors), "The affcetd sectors must be at least one!");
                return(Redirect("/Tasks/Create"));
            }

            tasksService.Create(model);

            return(Redirect("/"));
        }
Ejemplo n.º 4
0
        public void Create(TaskCreateInputModel model)
        {
            string[]         participantNames = model.Participants.Split(AffectedSectorSeperator);
            HashSet <string> participantIds   = new HashSet <string>();

            foreach (var participantName in participantNames)
            {
                Participant participant = context.Participants.FirstOrDefault(p => p.Name == participantName);
                if (participant == null)
                {
                    participant = new Participant {
                        Name = participantName
                    };
                    context.Participants.Add(participant);
                }

                participantIds.Add(participant.Id);
            }

            context.SaveChanges();

            HashSet <ParticipantTask> participantTasks = new HashSet <ParticipantTask>();

            foreach (var participanId in participantIds)
            {
                participantTasks.Add(new ParticipantTask {
                    ParticipantId = participanId
                });
            }

            Task task = new Task
            {
                AffectedSectors = string.Join(AffectedSectorSeperator, model.AffectedSectors),
                Description     = model.Description,
                Title           = model.Title,
                DueDate         = model.DueDate,
                Participants    = participantTasks,
            };

            context.Tasks.Add(task);
            context.SaveChanges();
        }
Ejemplo n.º 5
0
        public void CreateTask(TaskCreateInputModel model)
        {
            var participantsTokens = model.Participants.Split(", ", StringSplitOptions.RemoveEmptyEntries);
            var prtpnts            = new HashSet <UserTask>();

            foreach (var part in participantsTokens)
            {
                if (this.Db.Users.Any(u => u.Username == part))
                {
                    prtpnts.Add(new UserTask
                    {
                        UserId = this.Db.Users.First(u => u.Username == part).Id
                    });
                }
            }

            var sectors = new List <Sector>();

            if (model.AF_Customers != null)
            {
                sectors.Add(Sector.Customers);
            }

            if (model.AF_Finances != null)
            {
                sectors.Add(Sector.Finances);
            }

            if (model.AF_Internal != null)
            {
                sectors.Add(Sector.Internal);
            }

            if (model.AF_Management != null)
            {
                sectors.Add(Sector.Management);
            }

            if (model.AF_Marketing != null)
            {
                sectors.Add(Sector.Marketing);
            }

            var affSectors = new HashSet <TaskSector>();

            foreach (var sector in sectors)
            {
                affSectors.Add(new TaskSector
                {
                    Sector = sector
                });
            }

            var task = new Task
            {
                Title           = model.Title,
                DueDate         = model.DueDate,
                Description     = model.Description,
                Participants    = prtpnts,
                AffectedSectors = affSectors,
                IsReported      = false
            };

            this.Db.Tasks.Add(task);
            this.Db.SaveChanges();
        }