Ejemplo n.º 1
0
 // POST: api/Users - ADD or UPDATE
 public JsonResult<ModificationResult<UserDTO>> PostUser(UserDTO user)
 {
     var result = ValidateModelState<UserDTO>();
     if (result != null)
     {
         return result;
     }
     else
     {
         userManager.AddOrUpdateUser(user);
         return Json(new ModificationResult<UserDTO>(true)
         {
             Data = user
         });
     }
 }
Ejemplo n.º 2
0
        public void AddOrUpdateUser(UserDTO user)
        {
            using (var db = new NoteeContext())
            {
                var model = db.SubUsers.SingleOrDefault(u => u.UserID == user.UserID);
                if(model == null)
                {
                    model = db.SubUsers.Create();
                    model.UserID = user.UserID;
                    db.SubUsers.Add(model);
                }

                db.SaveChanges();
                user.UserID = model.UserID;

                new NotesManager().AddOrUpdateNotes(model.UserID, user.Notes);
                user.Notes.Clear();
                model.Notes.ToList().ForEach(n => user.Notes.Add(new NoteDTO(n)));
            }
        }