Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,TaskId,Description,Type,Criticality,Priority,CreateDate,EstimatedStartDate,EstimatedEndDate,RealStartDate,RealEndDate,EstimatedHours,ElapsedHours,PendingHours,Status,SubmoduleId,UserId")] Oesia.Models.Task task)
        {
            task.CreateDate   = DateTime.Now;
            task.PendingHours = task.EstimatedHours;
            task.Status       = "At risk";

            AppUser user = new AppUser();

            foreach (AppUser item in _services.GetUsersByRoleDB("Task manager"))
            {
                if (item.Id == task.UserId)
                {
                    user = item;
                }
            }

            // Create new obeject which links AppUsers and Tasks
            UserTask userTask = new UserTask
            {
                AppUsers = user,
                Tasks    = task
            };

            if (ModelState.IsValid)
            {
                _context.Add(task);
                _context.UserTask.Add(userTask);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,TaskId,Description,Type,Criticality,Priority,CreateDate,EstimatedStartDate,EstimatedEndDate,RealStartDate,RealEndDate,EstimatedHours,ElapsedHours,PendingHours,Status,SubmoduleId,UserId")] Oesia.Models.Task task)
        {
            AppUser user = new AppUser();

            foreach (AppUser userChoice in _services.GetUsersByRoleDB("Task manager"))
            {
                if (userChoice.Id == task.UserId)
                {
                    user = userChoice;
                }
            }

            UserTask userTask = new UserTask();

            userTask = await _context.UserTask.FirstOrDefaultAsync(x => x.AppUsers.Id == user.Id && x.Tasks.Id == task.Id);

            userTask.AppUsers = user;
            userTask.Tasks    = task;

            if (id != task.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(task);
                    _context.UserTask.Update(userTask);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TaskExists(task.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }