示例#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();
        }
示例#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();
        }
示例#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("Автомобиль добавлен");
        }
        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));
        }
示例#5
0
 public void AddUser(User user)
 {
     if (user == null)
     {
         Console.WriteLine("Ошибка! Попытка добавления пустого пользователя!");
     }
     else
     {
         appDBContent.Add(user);
         appDBContent.SaveChanges();
     }
 }
        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 );
        }
示例#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());
        }