Exemplo n.º 1
0
        public void Insert()
        {
            Person person = new Person {
                Name = "test", Company = _db.Companies.First()
            };

            _db.Add(person);
            _db.SaveChanges();

            List <Person> personList = new List <Person>
            {
                new Person {
                    Name = "test1", Company = _db.Companies.First()
                },
                new Person {
                    Name = "test2", Company = _db.Companies.First()
                },
                new Person {
                    Name = "test3", Company = _db.Companies.First()
                }
            };

            _db.Persons.AddRange(personList);
            _db.SaveChanges();
        }
        public async Task <IActionResult> Create([Bind("ProductId,Name,Category,Color,UnitPrice,AvailableQuantity,CratedDate")] Products products)
        {
            if (ModelState.IsValid)
            {
                _context.Add(products);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(products));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,Descricao,Referencia")] Categoria categoria)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categoria);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoria));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Name,SecondName,DateOfBirth")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
        public async Task <IActionResult> Create([Bind("Id,name")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Exemplo n.º 6
0
 public IActionResult New(Dish thisDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(thisDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("New", thisDish));
     }
 }
        public IActionResult Create(Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                _context.SaveChanges();

                TempData["message"] = "Person created!";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "There have been errors");
            return(View(person));
        }
Exemplo n.º 8
0
 public IActionResult CreateDish(Crud AllDishes)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(AllDishes);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         System.Console.WriteLine("error on adding dishes....this did not work");
         return(View("AddPage"));
     }
 }
Exemplo n.º 9
0
        public IActionResult Create(Person person)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "There were errors.");
                return(View(person));
            }

            _context.Add(person);
            _context.SaveChanges();

            TempData["message"] = "Person added";

            return(RedirectToAction("Index"));
        }
Exemplo n.º 10
0
        public IActionResult Create(Admins admin)
        {
            if (ModelState.IsValid)
            {
                admin.CreatedDate = System.DateTime.Now;
                _contextAdmin.Add(admin);
                _contextAdmin.SaveChanges();

                TempData["message"] = "Admin Created!";

                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "There has been errors");
            return(View(admin));
        }
Exemplo n.º 11
0
        public async Task <ActionResult> PostComment(string author, string commentContent)
        {
            if (author == string.Empty || commentContent == string.Empty)
            {
                return(RedirectToAction(nameof(Index)));
            }
            if (author == null || commentContent == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            Comment comment = new Comment()
            {
                Author         = author,
                Contents       = commentContent,
                DateOfCreation = DateTime.Now
            };

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

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult Create(Incident ticket)
        {
            if (ModelState.IsValid)
            {
                ticket.SubmittedDate = System.DateTime.Now;
                ticket.Status        = "Submitted";

                ticket.RequestorID = User.Identity.Name == null ? "Anomymous" : User.Identity.Name;

                ticket.requestLocation = city;
                ticket.latitute        = latitude;
                ticket.longtitude      = longtitude;
                _contextInc.Add(ticket);
                _contextInc.SaveChanges();

                TempData["message"] = "Ticket Created!";

                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "There has been errors");
            return(View(ticket));
        }