コード例 #1
0
        public JsonResponse Create(List list)
        {
            if (list == null)
            {
                return(new JsonResponse {
                    Result = "Failed",
                    Message = "Create requires an instance of list"
                });
            }
            if (!ModelState.IsValid)
            {
                return(new JsonResponse {
                    Result = "Failed",
                    Message = "Model state is invalid. See data.",
                    Error = ModelState
                });
            }

            db.Lists.Add(list);
            db.SaveChanges();
            return(new JsonResponse {
                Message = "Create successful.",
                Data = list
            });
        }
コード例 #2
0
        [HttpPost] //This method is receiving information from the view (in this case, a Super object)
        public IActionResult AddToDoList(ToDoList toDoList)
        {
            _ToDoListDb.ToDoList.Add(toDoList);
            _ToDoListDb.SaveChanges();               //Needed to save changed made to table.

            return(RedirectToAction(nameof(Index))); //Returns the Index view with (updated) List
        }
コード例 #3
0
ファイル: UsersController.cs プロジェクト: Jwils21/ToDoList
        public JsonResponse Create(User user)
        {
            if (user == null)
            {
                return(new JsonResponse {
                    Result = "Failed",
                    Message = "Create requires an instance of User"
                });
            }
            if (!ModelState.IsValid)
            {
                return(new JsonResponse {
                    Result = "Failed",
                    Message = "Model state is invalid. See data.",
                    Error = ModelState
                });
            }

            db.Users.Add(user);
            db.SaveChanges();
            return(new JsonResponse {
                Message = "Create successful.",
                Data = user
            });
        }
コード例 #4
0
        public void SeedFAQ()
        {
            try
            {
                var question1 = new FAQ {
                    Question = "What is ToDoList?", Answer = "ToDoList is a Web App for web site content and projects managing."
                };
                var question2 = new FAQ {
                    Question = "Is this available to my country?", Answer = "You can use ToDoList in all countries around the world, at your own risk."
                };
                var question3 = new FAQ {
                    Question = "How do I use the features of ToDoList App?", Answer = "If you want to use ToDoList, you need Azure or any other variant for SQL database and deploying. The code needed you can download from <a href=\"https://github.com/elvyra/ToDoList.git\" target=\"_blank\">GitHub repository</a>."
                };
                var question4 = new FAQ {
                    Question = "How much do the ToDoList App cost?", Answer = "ToDoList is absolutely free for all purposes (personal, learning and comercial). It was created for learning purposes, so be aware of using it on big data projects. We will appreciate your feedback and error reports, if any occours."
                };
                var question5 = new FAQ {
                    Question = "I have technical problem, who do I email?", Answer = "If you have any question, problem, offer or suggestion, please, contact us via facebook or linked (see the links at the bottom of the page)."
                };
                _context.AddRange(question1, question2, question3, question4, question5);

                _context.SaveChanges();
                _logger.LogInformation("Demo FAQ seeded to database.");
            }
            catch (Exception error)
            {
                _logger.LogError($"Demo FAQ seeding throw an exception. Error: ${error.Message}");
            }
        }
コード例 #5
0
        public IActionResult DeleteConfirmed(int id)
        {
            var thisCategory = _db.Categories.FirstOrDefault(categories => categories.CategoryId == id);

            _db.Categories.Remove(thisCategory);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public Board AddBoard(Board board)
        {
            _context.Board.Add(board);

            _context.SaveChanges();

            return(_context.Board.Last());
        }
コード例 #7
0
        public IActionResult DeleteConfirmed(int id)
        {
            var thisItem = _db.Items.FirstOrDefault(items => items.ItemId == id);

            _db.Items.Remove(thisItem);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #8
0
 public ActionResult Create(TaskItemViewModel taskItemViewModel)
 {
     toDoListDbContext.TaskItems.Add(new Domain.Entities.TaskItem {
         TaskDescription = taskItemViewModel.TaskDescription, TaskTitle = taskItemViewModel.TaskTitle, TaskDueDate = taskItemViewModel.TaskDueDate, UserId = User.Identity.GetUserId()
     });
     toDoListDbContext.SaveChanges();
     return(RedirectToAction("TaskList"));
 }
コード例 #9
0
        public ToDoListModel Create(ToDoListModel model, string login)
        {
            var user    = _dbContext.Users.Include(x => x.ToDoLists).SingleOrDefault(x => x.Login == login);
            var newToDo = _mapper.Map <DAL.Entities.ToDoList>(model);

            newToDo.CreationDate = DateTime.Now;
            user?.ToDoLists.Add(newToDo);
            _dbContext.SaveChanges();
            return(model);
        }
コード例 #10
0
 public IActionResult Create(Category category)
 {
     if (ModelState.IsValid)
     {
         _context.Categories.Add(category);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
コード例 #11
0
 public IActionResult Create(Item item)
 {
     if (ModelState.IsValid)
     {
         _context.Items.Add(item);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Categories = new SelectList(_context.Categories, "Categories", "Name");
     return(View(item));
 }
コード例 #12
0
        public ActionResult Create([Bind(Include = "Id,Name,DueDate,IsReOccuring")] ToDoList toDoList)
        {
            if (ModelState.IsValid)
            {
                db.ToDoLists.Add(toDoList);
                db.SaveChanges();
                return(RedirectToAction("Index")); //After an item added return to index Action -List
            }

            return(View(toDoList));
        }
コード例 #13
0
        public IActionResult AddToDoList(ToDoList todoList)
        {
            string activeUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (ModelState.IsValid)
            {
                todoList.UserId = activeUserId;
                _todoContext.ToDoList.Add(todoList);
                _todoContext.SaveChanges();//dont forget this  saves it back to sql
            }

            return(RedirectToAction("ToDoList"));//RedirectTo Action goes to method index
        }
コード例 #14
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }
        }
コード例 #15
0
 public ActionResult <ToDoListDTO> Create(ToDoListDTO toDoListDTO)
 {
     if (toDoListDTO != null)
     {
         var toDoList = mapper.Map <ToDoList>(toDoListDTO);
         context.ToDoLists.Add(toDoList);
         context.SaveChanges();
         toDoListDTO = mapper.Map <ToDoListDTO>(toDoList);
         return(toDoListDTO);
     }
     else
     {
         return(BadRequest());
     }
 }
コード例 #16
0
        public async Task <IActionResult> Post([FromBody] ListItem value)
        {
            await _context.ListItems.AddAsync(value);

            _context.SaveChanges();
            return(CreatedAtRoute("Get", new { value.Id }, value));
        }
コード例 #17
0
        public TaskItem AddTaskItem(int boardId, TaskItem taskitem)
        {
            var boardTaskItem = new BoardTaskItem();

            boardTaskItem.BoardId    = boardId;
            boardTaskItem.TaskItem   = taskitem;
            boardTaskItem.TaskItemId = taskitem.Id;

            _context.TaskItem.Add(taskitem);

            _context.BoardTaskItem.Add(boardTaskItem);

            _context.SaveChanges();

            return(_context.TaskItem.Last());
        }
コード例 #18
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
コード例 #19
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);
            _context.SaveChanges();
        }
コード例 #20
0
 public ActionResult Delete(Task task)
 {
     using (ToDoListDbContext db = new ToDoListDbContext())
     {
         db.Tasks.Attach(task);
         db.Entry(task).State = EntityState.Deleted;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #21
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
コード例 #22
0
        public Task MarkDone(Guid id)
        {
            var taskInDb = _context.Tasks.SingleOrDefault(t => t.Id == id);

            if (taskInDb != null)
            {
                try
                {
                    taskInDb.Status = Status.Done;
                    _context.SaveChanges();
                    return(taskInDb);
                }
                catch (Exception)
                {
                    _logger.LogError($"Error on task editing occoured. Task {id}");
                    return(null);
                }
            }
            _logger.LogError($"Task with Id {id} not found");
            return(null);
        }
コード例 #23
0
        public void AddTaskToList(int listItemId, ToDoListTask task)
        {
            _log.Debug("Check task is null");
            if (task == null)
            {
                _log.Error("Task not added");
                throw new ArgumentNullException("Task not added");
            }
            _log.Debug("Check value taskText is empty");
            if (string.IsNullOrEmpty(task.Text))
            {
                _log.Error("Field Text is empty");
                throw new ToDoListException("Field Text is empty");
            }

            _log.Debug("Check list exist in db");
            var list = _db.ToDoListItems.FirstOrDefault(l => l.Id == listItemId);

            _log.Debug("Check list is null");
            if (list == null)
            {
                _log.ErrorFormat("List with id {0} not found", listItemId);
                throw new ToDoListException(String.Format("List with id {0} not found", listItemId));
            }

            task.ToDoListItem = list;
            _log.Debug("Add task to list Tasks");
            list.Tasks.Add(task);
            _log.Debug("Add task to db");
            _db.SaveChanges();
            _log.Info("Task added to db");
        }
コード例 #24
0
 public ActionResult Create(Task task)
 {
     if (!ModelState.IsValid)
     {
         return(View(task));
     }
     using (ToDoListDbContext db = new ToDoListDbContext())
     {
         db.Entry(task).State = EntityState.Added;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
コード例 #25
0
        public Person DeleteUserByEmail(string email)
        {
            var person = _context.Persons.FirstOrDefaultAsync(p => p.Email == email).Result;

            if (person == null)
            {
                _logger.LogError($"Person with email {email} not found");
                return(null);
            }

            try
            {
                _context.Persons.Remove(person);
                _context.SaveChanges();
                return(person);
            }
            catch (Exception err)
            {
                _logger.LogError($"Error occoured while trying to remove person with email {email}: {err.Message}");
                return(null);
            }
        }
コード例 #26
0
 public ActionResult <ToDoItemDTO> Create(ToDoItemDTO toDoItemDTO)
 {
     if (toDoItemDTO != null)
     {
         var toDoList = context.ToDoLists.Find(toDoItemDTO.ToDoListId);
         if (toDoList != null)
         {
             var toDoItem = mapper.Map <ToDoItem>(toDoItemDTO);
             context.ToDoItems.Add(toDoItem);
             context.SaveChanges();
             toDoItemDTO = mapper.Map <ToDoItemDTO>(toDoItem);
             return(toDoItemDTO);
         }
         else
         {
             return(BadRequest("ToDoList Not found!"));
         }
     }
     else
     {
         return(BadRequest());
     }
 }
コード例 #27
0
        private void CreateDefaultTenant()
        {
            // Default tenant

            var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName);

            if (defaultTenant == null)
            {
                defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName);

                var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                if (defaultEdition != null)
                {
                    defaultTenant.EditionId = defaultEdition.Id;
                }

                _context.Tenants.Add(defaultTenant);
                _context.SaveChanges();
            }
        }
コード例 #28
0
        public void Create(User user)
        {
            _log.Debug("Check user is null");
            if (user == null)
            {
                _log.Error("Account not created.");
                throw new CreateUserFailedException("Account not created.");
            }
            _log.Debug("Check username or password or firstname or lastname or emailaddress are empty ");
            if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password) || string.IsNullOrEmpty(user.FirstName) ||
                string.IsNullOrEmpty(user.LastName) || string.IsNullOrEmpty(user.EmailAddress))
            {
                _log.Error("Field is empty");
                throw new CreateUserFailedException("Fill in all fields.");
            }

            _log.Debug("Add user to db");
            _db.Users.Add(user);
            _db.SaveChanges();
            _log.Info("User added to db");
        }
コード例 #29
0
 public Notes AddNote(Notes note)
 {
     _dbContext.Notes.Add(note);
     _dbContext.SaveChanges();
     return(note);
 }
コード例 #30
0
        private void CreateHostRoleAndUsers()
        {
            // Admin role for host

            var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role for host

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new ToDoListAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = null,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRoleForHost.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user for host

            var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (adminUserForHost == null)
            {
                var user = new User
                {
                    TenantId         = null,
                    UserName         = AbpUserBase.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    IsActive         = true
                };

                user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe");
                user.SetNormalizedNames();

                adminUserForHost = _context.Users.Add(user).Entity;
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

                _context.SaveChanges();
            }
        }