Ejemplo n.º 1
0
        public void EditAuthor(Author author)
        {
            var _author = appDBContent.Authors.FirstOrDefault(a => a.Id == author.Id);

            appDBContent.Remove(_author);
            appDBContent.Add(author);
            appDBContent.SaveChanges();
        }
Ejemplo n.º 2
0
        public void EditBook(Book book)
        {
            var _book = appDBContent.Books.FirstOrDefault(b => b.Id == book.Id);

            appDBContent.Remove(_book);
            appDBContent.Add(book);
            appDBContent.SaveChanges();
        }
Ejemplo n.º 3
0
        public Auto GetAuto(int autoId) => appDBContent.Auto.FirstOrDefault(p => p.Id == autoId);    //Search by ID

        public string AddAuto(Auto element)                                                          //Add object to DB
        {
            if (Autos.Select(s => s.Number == element.Number).Select(c => c == true).Contains(true)) //Validate if the object has already been added
            {
                return("Объект уже существует");
            }
            appDBContent.Add(element);
            appDBContent.SaveChanges();
            return("Автомобиль добавлен");
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Date,Text,User,UserCountry")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(comment));
        }
Ejemplo n.º 5
0
 public void AddUser(User user)
 {
     if (user == null)
     {
         Console.WriteLine("Ошибка! Попытка добавления пустого пользователя!");
     }
     else
     {
         appDBContent.Add(user);
         appDBContent.SaveChanges();
     }
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create(int id, DescCreateModel descriptions)
        {
            User Cuser = await _context.Users.FirstOrDefaultAsync(c => c.UserId == id);

            Descriptions desc = new Descriptions();

            desc.Description     = descriptions.Desc.Description;
            desc.UserCharacterId = Cuser;
            desc.UserAuthorId    = descriptions.UserAuthorId;

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

            return(RedirectToAction("Index", "User"));
            //return Content(descriptions.UserAuthorId+ "      " + descriptions.Desc.Description + "      "   + id );
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> New(CategoryListViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);

                var employee = new Category
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Image       = uniqueFileName,
                };
                dbContext.Add(employee);
                await dbContext.SaveChangesAsync();

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