public ActionResult Create([Bind(Include = "Id,Name")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "Id,Title,Description,IsComplete,TodoListId")] Todo todo)
        {
            if (ModelState.IsValid)
            {
                db.Todos.Add(todo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TodoListId = new SelectList(db.TodoLists, "Id", "Name", todo.TodoListId);
            return(View(todo));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "Id,Name,UserId")] TodoList todoList)
        {
            if (ModelState.IsValid)
            {
                db.TodoLists.Add(todoList);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "Id", "Name", todoList.UserId);
            return(View(todoList));
        }
        public IActionResult Create([FromBody] PersonDTO dto)
        {
            if (dto == null)
            {
                return(HttpBadRequest());
            }

            Person person = DTOToPerson(dto);

            _context.Persons.Add(person);
            _context.SaveChanges();
            return(CreatedAtRoute("GetPerson", new { controller = "Person", id = person.PersonId }, person));
        }
Esempio n. 5
0
 public HttpResponseMessage DeleteTag(int id)
 {
     try
     {
         using (var context = new TodoAppContext())
         {
             var user = AuthService.getCurrUserInfo(HttpContext.Current.Request.Headers);
             if (user == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.Unauthorized));
             }
             var c = context.tags.Where(t => t.tagID == id && t.createdBy == user.userID).FirstOrDefault();
             if (c == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound));
             }
             context.tags.Remove(c);
             context.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadGateway, e));
     }
 }
Esempio n. 6
0
        public HttpResponseMessage CreateTag(string newTagName)
        {
            try
            {
                using (var context = new TodoAppContext())
                {
                    var user = AuthService.getCurrUserInfo(HttpContext.Current.Request.Headers);
                    if (user == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }

                    var c = new Tags()
                    {
                        Name      = newTagName,
                        createdBy = user.userID
                    };
                    context.tags.Add(c);
                    context.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadGateway, e));
            }
        }
Esempio n. 7
0
 public HttpResponseMessage SignUp([FromBody] SignUpDTO newUser)
 {
     try
     {
         using (var context = new TodoAppContext())
         {
             using (MD5 md5Hash = MD5.Create())
             {
                 var c = new Users()
                 {
                     name     = newUser.name,
                     lastName = newUser.lastName,
                     password = GetMd5Hash(md5Hash, newUser.password),
                     username = newUser.username,
                     email    = newUser.email
                 };
                 context.users.Add(c);
                 context.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         };
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, e));
     }
 }
        public IActionResult Create([FromBody] TaskDTO dto, int personId)
        {
            if (dto == null)
            {
                return(HttpBadRequest());
            }

            Person person = _context.Persons.Single(x => x.PersonId == personId);

            if (person == null)
            {
                return(HttpBadRequest());
            }

            Task task = DTOToTask(dto);

            person.Tasks.Add(task);
            _context.SaveChanges();
            return(CreatedAtRoute("GetTask", new { controller = "Task", id = task.TaskId }, task));
        }
Esempio n. 9
0
        public ValuesController(TodoAppContext context)
        {
            _context = context;

            if (_context.TodoNotes.Count() == 0)
            {
                _context.TodoNotes.Add(new TodoNote {
                    Name = "Initial"
                });
                _context.SaveChanges();
            }
        }
Esempio n. 10
0
        public void Execute(int request)
        {
            var todo = _context.Todos.Find(request);

            if (todo == null)
            {
                throw new EntityNotFoundException(request, typeof(Todo));
            }

            _context.Todos.Remove(todo);
            _context.SaveChanges();
        }
Esempio n. 11
0
        public void Execute(TodoDto request)
        {
            _validator.ValidateAndThrow(request);

            Todo todo = new Todo
            {
                Name        = request.Name,
                Description = request.Description,
                Status      = request.Status
            };

            _context.Todos.Add(todo);
            _context.SaveChanges();
        }
Esempio n. 12
0
        public void Execute(TodoDto request)
        {
            _validator.ValidateAndThrow(request);

            var todo = _context.Todos.FirstOrDefault(x => x.Id == request.Id);

            if (todo == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Todo));
            }

            todo.Name        = request.Name;
            todo.Description = request.Description;
            todo.IsFinished  = request.IsFinished;
            todo.Status      = request.Status;

            _context.Todos.Update(todo);
            _context.SaveChanges();
        }
Esempio n. 13
0
        public static void Seed(this TodoAppContext dbContext)
        {
            dbContext.Todoes.Add(new Todoes
            {
                TodoId      = 1,
                Descripcion = "Test 1",
                Estatus     = "PENDIENTE",
                Documento   = "C:/prueba.jpg"
            });
            dbContext.Todoes.Add(new Todoes
            {
                TodoId      = 2,
                Descripcion = "Test 2",
                Estatus     = "PENDIENTE",
                Documento   = "C:/prueba.jpg"
            });

            dbContext.SaveChanges();
        }
Esempio n. 14
0
        public HttpResponseMessage createNewNote(newNoteDTO newNote)
        {
            try
            {
                using (var context = new TodoAppContext())
                {
                    var user = AuthService.getCurrUserInfo(HttpContext.Current.Request.Headers);
                    if (user == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }

                    var c = new Notes()
                    {
                        title        = newNote.title,
                        creationDate = DateTime.UtcNow,
                        description  = newNote.description,
                        dueDate      = DateTime.Parse(newNote.dueDate),
                        noteStatus   = Status.TODO,
                        noteType     = (Models.Type)newNote.type,
                        colorHex     = newNote.color,
                        remindMe     = (Models.remindMeType)newNote.remindMe,
                        createdBy    = user.userID
                    };
                    if (newNote.tagId != 0)
                    {
                        c.tagID   = newNote.tagId;
                        c.tagName = context.tags.Where(t => t.tagID == newNote.tagId).Select(d => d.Name).FirstOrDefault();
                    }

                    context.notes.Add(c);
                    context.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, c));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadGateway, e));
            }
        }
Esempio n. 15
0
        public HttpResponseMessage UpdateNote(UpdateNoteDTO note)
        {
            try
            {
                using (var context = new TodoAppContext())
                {
                    var user = AuthService.getCurrUserInfo(HttpContext.Current.Request.Headers);
                    if (user == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }

                    var c = context.notes.Where(n => n.noteID == note.noteID && n.createdBy == user.userID).FirstOrDefault();
                    if (c == null)
                    {
                        NotFound();
                    }
                    c.title       = note.title;
                    c.description = note.description;
                    c.dueDate     = DateTime.Parse(note.dueDate);
                    c.noteStatus  = Status.TODO;
                    c.noteType    = (Models.Type)note.type;
                    c.colorHex    = note.colorHex;
                    c.remindMe    = (Models.remindMeType)note.remindMe;
                    if (note.tagId != 0)
                    {
                        c.tagID   = note.tagId;
                        c.tagName = context.tags.Where(t => t.tagID == note.tagId).Select(d => d.Name).FirstOrDefault();
                    }
                    context.SaveChanges();
                    var result = context.notes.Where(n => n.createdBy == user.userID).ToList();
                    return(Request.CreateResponse(HttpStatusCode.OK, result));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadGateway, e));
            }
        }