public async Task <IActionResult> OnPost([Bind("id,taskName,isCompleted")] TodoItem todoItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(todoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(todoItem));
            }
        }
示例#2
0
        /// <summary>
        /// This method will recreate list of tasks, so it'll have correct ID's
        /// (if we remove 2nd elemend, we'll have 0, 1, 3 list, this method will rebuild it to 0, 1, 2)
        /// </summary>
        //private void RebuildList()
        //{
        //    for (int i = 0; i < ToDoList.Count; i++)
        //    {
        //        ToDoList[i].TaskId = i;
        //    }
        //}

        public async Task <IActionResult> New([Bind("TaskId,ShortName,Description")] ToDoModel tdModel, IFormFile uploadedFile)
        {
            if (!ModelState.IsValid)
            {
                return(View(tdModel));
            }

            tdModel.TaskId = 15;

            _context.Add(tdModel);

            if (uploadedFile != null)
            {
                string path = "/Files/" + uploadedFile.FileName;
                using (var filestraem = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(filestraem);
                }
                FileModel file = new FileModel {
                    Name = uploadedFile.FileName, Path = path
                };
                _context.File.Add(file);
                _context.SaveChanges();
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(List)));
        }
        public async Task <ToDoList> GetPopulatedToDoList()
        {
            var toDoItems = new List <ToDoItem>();

            for (int i = 0; i < 3; i++)
            {
                toDoItems.Add(new ToDoItem()
                {
                    UserId      = _authContext.UniqueIdentifier,
                    UpdatedBy   = Guid.NewGuid().ToString(),
                    CreatedBy   = Guid.NewGuid().ToString(),
                    CreatedDate = DateTime.Now,
                    UpdatedDate = DateTime.Now,
                    IsComplete  = false,
                    Name        = Guid.NewGuid().ToString()
                });
            }
            var toDoList = new ToDoList()
            {
                UserId      = _authContext.UniqueIdentifier,
                UpdatedBy   = Guid.NewGuid().ToString(),
                CreatedBy   = Guid.NewGuid().ToString(),
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now,
                Description = Guid.NewGuid().ToString(),
                Name        = Guid.NewGuid().ToString(),
                ToDoItems   = toDoItems
            };

            _context.Add(toDoList);
            await _context.SaveChangesAsync();

            return(toDoList);
        }
示例#4
0
 public OutputModel Post([FromBody] ToDoItem item)
 {
     try {
         if (ModelState.IsValid)
         {
             db.Add(item);
             db.SaveChanges();
             output.status  = "success";
             output.data    = item;
             output.message = "Data Baru Berhasil Disimpan";
         }
         else
         {
             output.status  = "error";
             output.message = "Data Baru Gagal Disimpan";
             output.data    = null;
         }
     }
     catch (Exception ex)
     {
         output.status  = "error";
         output.message = ex.Message;
         output.data    = null;
     }
     return(output);
 }
示例#5
0
 public Guid Post([FromBody] ToDoItem item)
 {
     item.Id          = Guid.NewGuid();
     item.CreatedDate = DateTime.Now;
     _context.Add(item);
     _context.SaveChanges();
     return(item.Id);
 }
示例#6
0
 public IActionResult NewToDoItem(ToDoModel model)
 {
     _ctx.Add(new ToDoItem {
         Task = model.NewItemName
     });
     _ctx.SaveChanges();
     return(Redirect("/"));
 }
示例#7
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content,Date")] ToDo toDo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(toDo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(toDo));
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("Id,TodoTask,DateCreated,DateStarted,DateFinish,TotalHours,Done")] ToDo toDo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(toDo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(toDo));
        }
示例#9
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Id,Title,Uid,UName,Type,Creator,Date,Msg")] Log log)
        {
            if (ModelState.IsValid)
            {
                _context.Add(log);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(log));
        }
示例#11
0
        public async Task <IActionResult> Create([Bind("Id,Value")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
示例#12
0
        public async Task <IActionResult> Create([Bind("ID,Title,ModifiedOn,Description,EstimatedHour")] ToDoItem toDoItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(toDoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(toDoItem));
        }
示例#13
0
        public async Task <IActionResult> Create([Bind("ID,Title,Date,Description,Status")] Tasks tasks)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tasks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tasks));
        }
示例#14
0
        public async Task <IActionResult> Create([Bind("Id,Task,Completed")] ToDoItem toDoItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(toDoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(toDoItem));
        }
示例#15
0
        public async Task <ActionResult> Create(TodoList item)
        {
            if (ModelState.IsValid)
            {
                _context.Add(item);
                await _context.SaveChangesAsync();

                TempData["Success"] = "İtem Başarıyla Eklendi!";
                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
示例#16
0
        public async Task <IActionResult> Create([Bind("Id,Name,StuId,AttributionId,Email,TeachName,PhoneNumber,EmergencyContact,MergencyPeoplePhone,Langtineadress")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Id = Guid.NewGuid().ToString();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("Id,classDescription,collegeId,majorId,classId,customerId")] Attribution attribution)
        {
            if (ModelState.IsValid)
            {
                attribution.Id = Guid.NewGuid().ToString();
                _context.Add(attribution);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(attribution));
        }
示例#18
0
        public async Task <ActionResult> Create(string Title)
        {
            //Console.WriteLine(Title);
            TodoList item = new TodoList();

            item.Title     = Title;
            item.IsChecked = false;
            context.Add(item);
            await context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(ToDoViewModel tasks)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tasks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(tasks));
        }
示例#20
0
        public async Task <ActionResult> Create(ToDo item)
        {
            if (ModelState.IsValid)
            {
                context.Add(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "Added the item successfully";
                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
示例#21
0
        public async Task <ActionResult> Create(TodoList item)
        {
            if (ModelState.IsValid)
            {
                context.Add(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "The item has been added!";

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
示例#22
0
 public ToDoItem CreateToDo([FromBody] ToDoItem item)
 {
     //ToDoUsers users = new ToDoUsers();
     if (item == null)
     {
     }
     _context.Add(item);
     //var result = (from td in _context.ToDoItems join tu in _context.ToDoUsers on td.UserID equals tu.ID select new { tu.FirstName, tu.LastName }).ToList();
     _context.SaveChanges();
     item.User           = (from user in _context.ToDoUsers where user.ID == item.UserID select user).FirstOrDefault();
     item.User.ToDoItems = (from items in _context.ToDoItems where items.UserID == item.UserID select new ToDoItem {
         ID = items.ID, IsComplete = items.IsComplete, Name = items.Name, UserID = items.UserID
     }).ToList();
     return(item);
 }
示例#23
0
        public List <IBaseModel> Save(List <IBaseModel> model)
        {
            IBaseEntity        mappedEntity     = null;
            List <IBaseEntity> returnedEntities = new List <IBaseEntity>();
            Type modelType = null;
            Type entityType;

            try
            {
                var toSave = model.Cast <IBaseModel>().ToList();

                if (model.Select(x => x.GetType())
                    .Distinct()
                    .Count() > 1)
                {
                    throw new Exception("Paramenter Dto must contain list of same type");
                }

                modelType = model.First().GetType();

                entityType = _mapper.ConfigurationProvider.GetAllTypeMaps()
                             .Where(x => x.SourceType == modelType)
                             .FirstOrDefault()
                             .DestinationType;

                using (ToDoContext context = new ToDoContext())
                {
                    foreach (var baseItem in model)
                    {
                        mappedEntity = _mapper.Map(baseItem, baseItem.GetType(), entityType) as IBaseEntity;
                        if (baseItem.ID == 0)
                        {
                            mappedEntity.CreatedDate = DateTime.UtcNow;
                            context.Add(mappedEntity);
                        }
                        returnedEntities.Add(mappedEntity);
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(returnedEntities.Select(x => _mapper.Map(x, entityType, modelType) as IBaseModel).ToList());
        }
示例#24
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description,Date")] ToDo dados)
        {
            //Verificando se todos dados obrigátorios foram preenchidos
            if (ModelState.IsValid)
            {
                //Salvando no banco e retornando a visão de listagem
                _context.Add(dados);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            /*Caso os dados estejam errados a página é regarregada,
             * com os memos dados para serem corrijidos.
             */
            return(View(dados));
        }
示例#25
0
 public IActionResult CreateUser([FromBody] Login user)
 {
     try
     {
         var newUser = _context.ToDoUsers.FirstOrDefault(u => u.FirstName == user.User.FirstName && u.LastName == user.User.LastName);
         if (newUser != null)
         {
             return(NotFound());
         }
         else
         {
             _context.Add(user);
             _context.SaveChanges();
             return(Ok(user));
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#26
0
        public static async Task SaveNewList()
        {
            try
            {
                var addToDoList = new ToDoListModel
                {
                    ListName   = CreateNewListViewModel.ListName,
                    LastUpdate = DateTime.Now
                };

                await using var toDoContext = new ToDoContext();
                toDoContext.Add(addToDoList);
                await toDoContext.SaveChangesAsync();

                PostToDoList(toDoContext);
            }
            catch (Exception ex)
            {
                //Handle exception - Typically I use a service like rollbar
                Debug.WriteLine(ex);
            }
        }
示例#27
0
 public void AddUser(User user)
 {
     context.Add(user);
     context.SaveChanges();
 }
示例#28
0
 public void Create(ToDo thing)
 {
     context.Add(thing);
     context.SaveChanges();
 }
示例#29
0
 public IActionResult Add(ToDo todo)
 {
     todoContext.Add(todo);
     todoContext.SaveChanges();
     return(Redirect("add"));
 }
示例#30
0
        public static void EnshurePopulated(IApplicationBuilder builder)
        {
            ToDoContext context = (ToDoContext)builder.ApplicationServices.GetService(typeof(ToDoContext));
            UserManager <UserEntity> userManager = (UserManager <UserEntity>)builder.ApplicationServices.GetService(typeof(UserManager <UserEntity>));

            context.Database.Migrate();

            if (userManager.Users.Count() == 0)
            {
                userManager.CreateAsync(new UserEntity {
                    Email = "*****@*****.**", UserName = "******"
                }, "123Qweasd!").Wait();
            }

            if (!context.Tasks.Any())
            {
                TagEntity[] tags = new TagEntity[]
                {
                    new TagEntity {
                        Name = "Продукти", Color = "#32a842"
                    },
                    new TagEntity {
                        Name = "М'ясо", Color = "#c70442"
                    },
                    new TagEntity {
                        Name = "Пиво", Color = "#94007b"
                    },
                    new TagEntity {
                        Name = "Уроки", Color = "#002594"
                    },
                    new TagEntity {
                        Name = "WebApi", Color = "#19223d"
                    }
                };

                context.AddRange(tags);

                CategoryEntity[] categories = new CategoryEntity[]
                {
                    new CategoryEntity {
                        Name = "Навчання"
                    },
                    new CategoryEntity {
                        Name = "Їжа"
                    },
                    new CategoryEntity {
                        Name = "Відпочинок"
                    },
                };

                context.AddRange(categories);

                Task <UserEntity> task = userManager.FindByEmailAsync("*****@*****.**");
                task.Wait();
                UserEntity userEntity = task.Result;

                //addTasks
                TaskEntity task1 = new TaskEntity
                {
                    Description = "Зробити домашку по WebApi",
                    Category    = categories[0],
                    Date        = DateTime.Now - TimeSpan.FromDays(1),
                    Priority    = 1,
                    User        = userEntity
                };

                context.Add <TaskEntity>(task1);
                ICollection <TagEntity> tags1 = new List <TagEntity>()
                {
                    tags[3], tags[4]
                };
                task1.Tags = new List <TaskTag>();
                foreach (var tag in tags1)
                {
                    task1.Tags.Add(new TaskTag {
                        Task = task1, Tag = tag
                    });
                }

                TaskEntity task2 = new TaskEntity
                {
                    Description = "Випити пивка з друзями",
                    Category    = categories[2],
                    Date        = DateTime.Now + TimeSpan.FromDays(1),
                    Priority    = 5,
                    User        = userEntity
                };

                context.Add <TaskEntity>(task2);
                ICollection <TagEntity> tags2 = new List <TagEntity>()
                {
                    tags[0], tags[2]
                };
                task2.Tags = new List <TaskTag>();
                foreach (var tag in tags2)
                {
                    task2.Tags.Add(new TaskTag {
                        Task = task2, Tag = tag
                    });
                }

                context.SaveChanges();
            }
        }