Esempio n. 1
0
        public async Task EditPostShouldEditListCorrectly()
        {
            this.FillDatabase();

            this.viewModel = new ToDoListViewModel
            {
                Id        = "list1",
                Name      = "Shoplist Edited",
                Status    = ViewModels.ToDoLists.Enums.StatusType.Completed,
                ListItems = new List <string>(),
            };

            this.viewModel.ListItems.Add("test item");

            var result = await this.controller.Edit(this.viewModel, "/ToDoLists/AllLists");

            var viewResult = Assert.IsType <RedirectResult>(result);

            var list = this.db.ToDoLists.FirstOrDefault(x => x.Id == "list1");

            Assert.Equal("Shoplist Edited", list.Name);
            Assert.Equal(4, list.ListItems.Count());
            Assert.True(list.ListItems.Any(li => li.Name == "test item"));
            Assert.True(list.Status == StatusType.Completed);
        }
Esempio n. 2
0
 public async Task<IActionResult> List(string userid)
 {
     if(userid == null && !User.Identity.IsAuthenticated) // if no user is currently logged in 
     {
         
         return RedirectToAction("index", "home"); // return to home
     }
     //else try to obtain a user model
     try
     {
         User user = null;
         if (User.Identity.IsAuthenticated)
             user = await _userManager.FindByNameAsync(User.Identity.Name);
         else
             user = await _userManager.FindByIdAsync(userid);
         var todos = new List<ToDoItem>();
         using (var context = new ToDoListDBContext())
         {
             todos = context.ToDoItem.Where(item => item.UserId == user.Id).ToList();
         }
         var viewModel = new ToDoListViewModel() { IdentityUser = user, ToDoItems = todos };
         return View(viewModel);
     }
     catch(Exception e)
     {
         return RedirectToAction("error", "home", new { error = e.Message });
     }
 }
Esempio n. 3
0
        public ActionResult Index()
        {
            var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>();
            var userId  = User.Identity.GetUserId();

            //student - get all assignments from enrollments
            var currentEnrollmentsWithAssignments = context.Enrollments.Where(x => x.User.Id == userId).Include(x => x.User).Include(x => x.Course).Include("Course.Assignments").ToList();

            //student - get all upcoming assignments and sort them by due date
            var allAssignments         = currentEnrollmentsWithAssignments.Select(x => x.Course).SelectMany(y => y.Assignments).ToList();
            var allRelevantAssignments = allAssignments.Where(x => x.DueDate > DateTime.Now.Date).ToList();
            var allAssignmentsSorted   = allRelevantAssignments.OrderBy(x => x.DueDate).ToList();

            //instructor - get all courses
            var currentInstructor        = context.Users.Where(x => x.Id == userId).FirstOrDefault();
            var currentInstructorCourses = context.Courses.Where(x => x.Instructor.Id == currentInstructor.Id).ToList();

            //instructor - get all upcoming assignments from those courses and sort them by due date
            var allInstructorAssignments               = currentInstructorCourses.SelectMany(y => y.Assignments).ToList();
            var allRelevantInstructorAssignments       = allInstructorAssignments.Where(x => x.DueDate > DateTime.Now.Date).ToList();
            var allRelevantInstructorAssignmentsSorted = allRelevantInstructorAssignments.OrderBy(x => x.DueDate).ToList();

            var toDoListViewModel = new ToDoListViewModel()
            {
                currentAssignmentsView           = allAssignmentsSorted,
                currentEnrollmentsView           = currentEnrollmentsWithAssignments,
                currentCoursesView               = currentInstructorCourses,
                currentInstructorAssignmentsView = allRelevantInstructorAssignmentsSorted
            };

            return(View(toDoListViewModel));
        }
Esempio n. 4
0
        public IActionResult Edit(int id)
        {
            ToDoListViewModel viewModel = new ToDoListViewModel();

            viewModel.EditableItem = viewModel.ToDoItems.FirstOrDefault(x => x.Id == id);
            return(View("Index", viewModel));
        }
 public IActionResult CreateUpdate(ToDoListViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         DbHelper dbHelper = new DbHelper();
         using (var db = new SqliteConnection(dbHelper.GetConnection().ConnectionString))
         {
             db.Open();
             if (viewModel.EditableItem.Id <= 0)
             {
                 viewModel.EditableItem.DateAdded = DateTime.Now;
                 var insertCmd = db.CreateCommand();
                 insertCmd.CommandText = "INSERT INTO todo_items (add_date,title,is_done) VALUES (@date, @title, 0)";
                 insertCmd.Parameters.AddWithValue("date", viewModel.EditableItem.DateAdded);
                 insertCmd.Parameters.AddWithValue("title", viewModel.EditableItem.Title);
                 insertCmd.ExecuteNonQuery();
             }
             else
             {
                 var updateCmd = db.CreateCommand();
                 updateCmd.CommandText = $"UPDATE todo_items SET title = @title WHERE id = @id";
                 updateCmd.Parameters.AddWithValue("title", viewModel.EditableItem.Title);
                 updateCmd.Parameters.AddWithValue("id", viewModel.EditableItem.Id);
                 updateCmd.ExecuteNonQuery();
             }
         }
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("Index", new ToDoListViewModel()));
     }
 }
Esempio n. 6
0
        // POST api/<controller>
        public IHttpActionResult Post(ToDoListViewModel toDoListViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            bool isSaved = false;

            using (var ctx = new ToDoListDBEntities())
            {
                ctx.tblToDoLists.Add(new tblToDoList()
                {
                    Title       = toDoListViewModel.Title,
                    Description = toDoListViewModel.Description,
                    CreatedOn   = DateTime.Now
                });

                ctx.SaveChanges();
                isSaved = true;
            }

            if (isSaved)
            {
                return(Ok(toDoListViewModel));
            }
            else
            {
                return(BadRequest("Error occured while saving data"));
            }
        }
Esempio n. 7
0
        // PUT api/<controller>/5
        public IHttpActionResult Put(ToDoListViewModel todoListModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new ToDoListDBEntities())
            {
                var existingRecord = ctx.tblToDoLists.Where(s => s.ID == todoListModel.ID)
                                     .FirstOrDefault <tblToDoList>();

                if (existingRecord != null)
                {
                    existingRecord.Title       = todoListModel.Title;
                    existingRecord.Description = todoListModel.Description;
                    existingRecord.ModifiedOn  = DateTime.Now;

                    ctx.SaveChanges();
                }
                else
                {
                    return(BadRequest("Record not found"));
                }
            }

            return(Ok(todoListModel));
        }
Esempio n. 8
0
 public IActionResult CreateUpdate(ToDoListViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         using (var db = DbHelper.GetConnection())
         {
             if (viewModel.EditableItem.Id <= 0)
             {
                 viewModel.EditableItem.AddDate = DateTime.Now;
                 db.Insert <ToDoListItem>(viewModel.EditableItem);
             }
             else
             {
                 ToDoListItem dbItem = db.Get <ToDoListItem>(viewModel.EditableItem.Id);
                 TryUpdateModelAsync <ToDoListItem>(dbItem, "EditableItem");
                 db.Update <ToDoListItem>(dbItem);
             }
         }
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("Index", new ToDoListViewModel()));
     }
 }
        public ViewModelLocator()
        {
            navigationService = new NavigationService();

            var builder = new ContainerBuilder();

            builder.RegisterType <AppViewModel>();
            builder.RegisterType <ToDoListViewModel>();
            builder.RegisterType <AddTaskViewModel>();
            builder.RegisterType <JsonSaveLoadService>().As <ISaveLoadService>().InstancePerLifetimeScope();
            builder.RegisterInstance(navigationService).As <INavigationService>();
            var container = builder.Build();

            using (var scope = container.BeginLifetimeScope())
            {
                appViewModel      = scope.Resolve <AppViewModel>();
                toDoListViewModel = scope.Resolve <ToDoListViewModel>();
                addTaskViewModel  = scope.Resolve <AddTaskViewModel>();
            };

            MainViewModel = appViewModel;

            navigationService.AddPage(toDoListViewModel, VM.ToDoList);
            navigationService.AddPage(addTaskViewModel, VM.AddTask);

            navigationService.NavigateTo(VM.ToDoList);
        }
Esempio n. 10
0
        public IActionResult Details(int Id)
        {
            ToDoList          model  = GetOneToDo(Id);
            ToDoListViewModel result = GetToDoViewModelFromEntitiy(model);

            return(View(result));
        }
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new ToDoListViewModel();
     context     = DataContext as ToDoListViewModel;
     context.OnToDoListUpdated += Context_OnToDoListUpdated;
 }
Esempio n. 12
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DataBank db       = new DataBank();
            ToDoList toDoList = db.GetToDolistItem(id);

            if (toDoList == null)
            {
                return(HttpNotFound());
            }
            toDoList.Resource = db.GetResource(Convert.ToInt32(Session["ResId"]));
            ToDoListViewModel viewModel = new ToDoListViewModel();

            viewModel.ID          = toDoList.ID;
            viewModel.Title       = toDoList.Title;
            viewModel.Content     = toDoList.Content;
            viewModel.CreatedDate = toDoList.CreatedDate;
            viewModel.Done        = toDoList.Done;
            viewModel.DueDate     = toDoList.DueDate;
            viewModel.Prority     = toDoList.Prority;
            return(View(viewModel));
        }
Esempio n. 13
0
        public ActionResult Details(int?id)
        {
            MethodBank mb     = new MethodBank();
            int        userId = Convert.ToInt32(Session["UserID"]);
            int        subId  = Convert.ToInt32(Session["SubcriptionId"]);
            int        resId  = Convert.ToInt32(Session["ResId"]);

            if (id == null || !mb.UseResource(userId, subId, resId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DataBank db       = new DataBank();
            ToDoList toDoList = db.GetToDolistItem(id);

            if (toDoList == null)
            {
                return(HttpNotFound());
            }
            toDoList.Resource = db.GetResource(Convert.ToInt32(Session["ResId"]));
            ToDoListViewModel viewModel = new ToDoListViewModel();

            viewModel.ID          = toDoList.ID;
            viewModel.Title       = toDoList.Title;
            viewModel.Content     = toDoList.Content;
            viewModel.CreatedDate = toDoList.CreatedDate;
            viewModel.Done        = toDoList.Done;
            viewModel.DueDate     = toDoList.DueDate;
            viewModel.Prority     = toDoList.Prority;
            return(View(viewModel));
        }
Esempio n. 14
0
        // TODO: create view component to exclude script for adding new items => id must be different in every list
        // In categories and everwhere where use modal for edit/delete - TOO!
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                var user = await this.userManager.GetUserAsync(this.User);

                var dto = await this.toDoListsService.GetByIdAsync(user.Id, id);

                var model = new ToDoListViewModel()
                {
                    Id        = dto.Id,
                    CreatedOn = dto.CreatedOn,
                    Name      = dto.Name,
                    Status    = Enum.Parse <StatusType>(dto.Status.ToString()),
                    Items     = dto.ListItems.Select(li => new ToDoItemViewModel
                    {
                        Id        = li.Id,
                        Name      = li.Name,
                        Status    = Enum.Parse <StatusType>(li.Status.ToString()),
                        CreatedOn = li.CreatedOn,
                    })
                                .OrderBy(li => li.CreatedOn)
                                .ToList(),
                };

                return(this.View(model));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }
Esempio n. 15
0
        public ActionResult Index()
        {
            ToDoListViewModel viewModel = new ToDoListViewModel();
            var taskList = _taskService.GetAll();

            viewModel.ToDoTasks = taskList;
            return(View(viewModel));
        }
Esempio n. 16
0
 public void Create(ToDoListViewModel x)
 {
     toDoList.Subject       = x.toDoList.Subject;
     toDoList.Status        = false;
     listViewModel.toDoList = toDoList;
     db.ToDoListModels.Add(listViewModel.toDoList);
     db.SaveChanges();
 }
 public ActionResult Create(ToDoListViewModel x)
 {
     if (ModelState.IsValid)
     {
         new ToDoListRepository().Create(x);
         return(RedirectToAction("Index", listViewModel.toDoList));
     }
     return(View());
 }
Esempio n. 18
0
        public ActionResult Edit(string id)
        {
            Guard.WhenArgument(id, "id").IsNullOrEmpty().Throw();

            var list       = this.toDoListModelService.GetListById(Guid.Parse(id));
            var mappedList = new ToDoListViewModel(list);

            return(this.View(mappedList));
        }
Esempio n. 19
0
        public ActionResult Index(string id)
        {
            Guard.WhenArgument(id, "id").IsNullOrEmpty().Throw();

            TempData["ListId"] = id;
            var selectedList = this.toDoListModelService.GetListById(Guid.Parse(id));
            var mappedList   = new ToDoListViewModel(selectedList);

            return(this.View(mappedList));
        }
Esempio n. 20
0
        public IActionResult Edit(int Id)
        {
            ToDoList          model  = GetOneToDo(Id);
            ToDoListViewModel result = null;

            if (model != null)
            {
                result = GetToDoViewModelFromEntitiy(model);
            }
            return(View(result));
        }
Esempio n. 21
0
        public IActionResult Razor(ToDoListViewModel toDoListViewModel)
        {
            var newItem = new ToDoViewModel
            {
                Id   = toDoListViewModel.ToDos.Count > 0 ? toDoListViewModel.ToDos[toDoListViewModel.ToDos.Count - 1].Id + 1 : 0,
                Name = toDoListViewModel.NewTask
            };

            toDoListViewModel.NewTask = string.Empty;
            toDoListViewModel.ToDos.Add(newItem);
            return(View(toDoListViewModel));
        }
Esempio n. 22
0
        public ActionResult Create(ToDoListViewModel newList)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(newList));
            }

            var userId      = User.Identity.GetUserId();
            var currentUser = this.userService.GetUserById(userId);

            this.toDoListModelService.CreateToDoList(currentUser, newList.Name, newList.IsPublic, newList.Category);

            return(RedirectToAction("ListsAndTasks", "ToDoList"));
        }
        public IActionResult Index(string key)
        {
            var toDos = _toDoHelper.Get("toDo");

            if (key != null)
            {
                toDos = toDos.Where(t => t.Title.ToLower().Contains(key.ToLower())).ToList();
            }

            var model = new ToDoListViewModel()
            {
                ToDos = toDos
            };

            return(View(model));
        }
Esempio n. 24
0
        public IActionResult Edit(ToDoListViewModel model)
        {
            ToDoList entity = GetOneToDo(model.Id);

            if (entity != null)
            {
                entity.Name      = model.Name;
                entity.ToDo      = model.ToDo;
                entity.StartDate = !string.IsNullOrEmpty(model.StartDate) ? (DateTime?)Convert.ToDateTime(model.StartDate) : null;
                entity.EndDate   = !string.IsNullOrEmpty(model.EndDate) ? (DateTime?)Convert.ToDateTime(model.EndDate) : null;

                _context.SaveChanges();
            }
            ;

            return(RedirectToAction("ToDoList"));
        }
Esempio n. 25
0
        public async Task <IActionResult> Index()
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var tasks = await _toDoListTaskService.GetUnfinishedTasksAsync(currentUser);

            var model = new ToDoListViewModel()
            {
                Tasks = tasks
            };

            return(View(model));
        }
Esempio n. 26
0
        public ActionResult EditList(string id, ToDoListViewModel editList)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(editList));
            }
            Guard.WhenArgument(id, "id").IsNullOrEmpty().Throw();

            var listToBeEdited = this.toDoListModelService.GetListById(Guid.Parse(id));

            listToBeEdited.Name     = editList.Name;
            listToBeEdited.IsPublic = editList.IsPublic;
            listToBeEdited.Category = editList.Category;
            listToBeEdited.Date     = DateTime.Now;

            this.toDoListModelService.UpdateToDoList(listToBeEdited);

            return(RedirectToAction("ListsAndTasks", "ToDoList"));
        }
Esempio n. 27
0
        public async Task <IActionResult> Edit(ToDoListViewModel todolist)
        {
            var todoListDB = await _toDoList.GetEntityById(todolist.Id);

            if (ModelState.IsValid)
            {
                todoListDB.Title    = todolist.Title;
                todoListDB.Done     = todolist.Done;
                todoListDB.Date     = DateTime.Now;
                todoListDB.UserName = _accessor.HttpContext.Session.GetString("UserNameSession");

                TempData["success"] = "Task has been Edited!";
                await _toDoList.Update(todoListDB);

                return(RedirectToAction("Index"));
            }
            TempData["error"] = "Something went wrong!";
            return(View(todolist));
        }
Esempio n. 28
0
        public List <ToDoListViewModel> tolist([FromForm] string email)
        {
            ToDoListViewModel        todoobj     = new ToDoListViewModel();
            List <ToDoListViewModel> todolistobj = new List <ToDoListViewModel>();

            try
            {
                if (_customer.CheckCustomerEmailExisting(email).Number.Equals(1))
                {
                    AirPortModel.Models.Customer customerobj = _customer.FindByEmail(email);
                    if (_flighttodo.FindByCustumerId(customerobj.Id) != null)
                    {
                        var listtodo = _flighttodo.FindByCustumerId(customerobj.Id);
                        foreach (var item in listtodo)
                        {
                            todoobj.id          = item.id;
                            todoobj.Name        = item.Name;
                            todoobj.LastUpdate  = item.LastUpdate;
                            todoobj.IsDon       = item.IsDon;
                            todoobj.FlightId    = item.FlightId;
                            todoobj.DateCreate  = item.DateCreate;
                            todoobj.Description = item.Description;
                            todoobj.LastUpdate  = item.LastUpdate;
                            todolistobj.Add(todoobj);
                        }
                        return(todolistobj);
                    }
                    else
                    {
                        return(todolistobj);
                    }
                }
                else
                {
                    return(todolistobj);
                }
            }
            catch (Exception ex)
            {
                string mes = ex.Message;
                return(todolistobj);
            }
        }
Esempio n. 29
0
        public IActionResult Create(ToDoListViewModel model)
        {
            if (ModelState.IsValid)
            {
                var todoList = model;

                _context.ToDoLists.Add(new Models.ToDoList()
                {
                    Name      = model.Name,
                    ToDo      = model.ToDo,
                    StartDate = string.IsNullOrEmpty(model.StartDate)?null:(DateTime?)Convert.ToDateTime(model.StartDate),
                    EndDate   = string.IsNullOrEmpty(model.EndDate)?null:(DateTime?)Convert.ToDateTime(model.EndDate)
                });

                _context.SaveChanges();
            }

            return(RedirectToAction("ToDoList"));
        }
Esempio n. 30
0
        public async Task <IActionResult> Create(ToDoListViewModel todolist)
        {
            ToDoList todoListDB = new ToDoList();

            if (ModelState.IsValid)
            {
                todoListDB.Title       = todolist.Title;
                todoListDB.UserName    = _accessor.HttpContext.Session.GetString("UserNameSession");
                todoListDB.Description = todolist.Description;
                todoListDB.Date        = DateTime.Now;
                todoListDB.Done        = false;

                TempData["success"] = "Task has been created!";
                await _toDoList.Add(todoListDB);

                return(RedirectToAction("Index"));
            }
            TempData["error"] = "Something went wrong!";
            return(View(todolist));
        }