public async Task <IActionResult> UpdateTask(int id, PrivateTask task)
        {
            if (id != task.TaskId)
            {
                return(BadRequest());
            }

            var requestedTask = await _ctx.PrivateTasks
                                .SingleOrDefaultAsync(t => t.TaskId == id);

            if (requestedTask == null)
            {
                return(NotFound());
            }

            //picking desired attributes in case id or ownership was wrongly changed
            requestedTask.Title       = task.Title;
            requestedTask.Description = task.Description;
            requestedTask.Checklists  = task.Checklists;


            try
            {
                await _ctx.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!TaskExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> RegisterMembership(int groupId, string[] memberUsernames)
        {
            string username = HttpContext.User.Identity.Name;

            if (!AdminIsValid(username, groupId))
            {
                return(Unauthorized());
            }

            var memberships = _ctx.Memberships;

            //if any of the entries is faulty then nothing gets saved. A whole transaction
            try
            {
                foreach (var member in memberUsernames)
                {
                    memberships.Add(new UserGroup()
                    {
                        GroupID        = groupId,
                        MemberUsername = member
                    });
                }

                await _ctx.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("Information,IsCommercial")] Address address)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(address);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                } catch (DbUpdateException ex)
                {
                    if (ex.HResult == -2146233088)
                    {
                        ModelState.AddModelError("", @"Unable to save changes.
                                                       Address already exists");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                }
            }
            return(View(address));
        }
Beispiel #4
0
        public async Task <IActionResult> AddOrEdit([Bind("ManagerNotesId,Title,TextOfNote")] ManagerNote managerNote)
        {
            if (ModelState.IsValid)
            {
                if (managerNote.ManagerNotesId == 0)
                {
                    _context.Add(managerNote);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    _context.Update(managerNote);
                    await _context.SaveChangesAsync();

                    return(RedirectToRoute(new
                    {
                        controller = "ManagerNote",
                        action = "Index",
                        titleOfNote = managerNote.Title
                    }));
                }
            }
            return(View(managerNote));
        }
        public async Task <IActionResult> CreateGroup(GroupDTO groupInput)
        {
            string username = HttpContext.User.Identity.Name;

            Group newGroup = new Group()
            {
                AdminUsername = username,
                title         = groupInput.Title,
                Description   = groupInput.Description,
                CreatedDate   = DateTime.Now.ToString("MM/dd/yyyy")
            };

            _ctx.Groups.Add(newGroup);


            try
            {
                await _ctx.SaveChangesAsync();

                //make the admin also a member of his own group
                _ctx.Memberships.Add(new UserGroup()
                {
                    MemberUsername = username,
                    GroupID        = newGroup.GroupId,
                });
                await _ctx.SaveChangesAsync();

                return(Ok(newGroup));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }
Beispiel #6
0
        public virtual async Task <T> Create(T obj)
        {
            _context.Add(obj);
            await _context.SaveChangesAsync();

            return(obj);
        }
Beispiel #7
0
        public async Task <IActionResult> Create([Bind("Name,Description,UserID")] Department department)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(department);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                } catch (DbUpdateException ex)
                {
                    if (ex.HResult == -2146233088)
                    {
                        ModelState.AddModelError("", @"Unable to save changes.
                                                       Department already exists");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                }
            }
            ViewData["UserID"] = new SelectList(_context.User, "ID", "Name", department.UserID);
            return(View(department));
        }
Beispiel #8
0
        public async Task <IActionResult> Update(int groupId, int taskId, SharedTasks task)
        {
            string username = HttpContext.User.Identity.Name;

            if (taskId != task.TaskId)
            {
                return(BadRequest());
            }

            //verify group and task
            var group = _ctx.Groups
                        .Include(g => g.SharedTasks)
                        .ToList()
                        .FirstOrDefault(g => g.GroupId == groupId);

            if (group == null || group.AdminUsername != username)
            {
                return(Unauthorized());
            }

            int index = group.SharedTasks.FindIndex(t => t.GroupId == taskId);

            if (index == -1)
            {
                return(BadRequest());
            }

            group.SharedTasks[index] = task;

            await _ctx.SaveChangesAsync();

            return(Ok(task));
        }
Beispiel #9
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,Creator,CreationDate")] Topic topic)
        {
            if (ModelState.IsValid)
            {
                var claimsIdentity = User.Identity as ClaimsIdentity;
                if (claimsIdentity != null)
                {
                    var userIdClaim = claimsIdentity.Claims
                                      .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

                    if (userIdClaim != null)
                    {
                        var userIdValue = userIdClaim.Value;
                        topic.Creator = userIdValue;
                    }
                }

                topic.Id = Guid.NewGuid();
                _context.Add(topic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Creator"] = new SelectList(_context.Users, "Id", "Id", topic.Creator);
            return(View(topic));
        }
        public async Task <IActionResult> Create(
            [Bind("Name,Age,Email,Description")] User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            } catch (DbUpdateException ex)
            {
                if (ex.HResult == -2146233088)
                {
                    ModelState.AddModelError("", @"Unable to save changes.
                                                       User already exists");
                }
                else
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            return(View(user));
        }
Beispiel #11
0
        public async Task <IActionResult> Create([Bind("ManagerID,FirstName,LastName,Department")] Manager manager)
        {
            if (ModelState.IsValid)
            {
                _context.Add(manager);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(manager));
        }
Beispiel #12
0
        public async Task <IActionResult> Create(Job job)
        {
            if (ModelState.IsValid)
            {
                db.Jobs.Add(job);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(job));
        }
Beispiel #13
0
        public async Task <IActionResult> Create([Bind("Id,ProjectName,NumberOfWorkers")] Proekt proekt)
        {
            if (ModelState.IsValid)
            {
                _context.Add(proekt);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(proekt));
        }
        public async Task <IHttpActionResult> Post(Manager manager)
        {
            manager.Id = Guid.NewGuid();
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            db.Managers.Add(manager);
            await db.SaveChangesAsync();

            return(Created(manager));
        }
Beispiel #15
0
        public async Task <IActionResult> Create(AndroidViewModel androidView)
        {
            if (ModelState.IsValid)
            {
                Android android = (Android)androidView;
                android.Reability = 10;
                android.Status    = 1;
                db.Androids.Add(android);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(androidView));
        }
        public async Task <IActionResult> Create([Bind("Name,Surname,Email")] Programist programist)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(programist);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(programist));
        }
Beispiel #17
0
        public async Task <IActionResult> Delete(string email)
        {
            if (email == null)
            {
                return(BadRequest());
            }

            var acc = await _context.Accounts.SingleOrDefaultAsync(a => a.Email == email);

            if (acc == null)
            {
                return(NotFound());
            }

            _context.Accounts.Remove(acc);
            await _context.SaveChangesAsync();

            return(Ok());
        }