示例#1
0
 public IActionResult AddChef(Chef chef)
 {
     if (ModelState.IsValid)
     {
         var      now      = DateTime.Today;
         var      chefAge  = now - chef.Age;
         DateTime day1     = new DateTime(2018, 1, 1);
         DateTime day2     = new DateTime(2000, 1, 1);
         var      eighteen = day1 - day2;
         if (chefAge > eighteen)
         {
             dbContext.Add(chef);
             dbContext.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("Age", "Age should be minimum 18");
             return(View("new"));
         }
     }
     else
     {
         return(View("new"));
     }
 }
示例#2
0
 public ActionResult AddEditBooks(long?id, BookViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool  isNew = !id.HasValue;
             Books book  = isNew ? new Books
             {
                 AddedDate = DateTime.UtcNow
             } : context.Set <Books>().SingleOrDefault(s => s.Id == id.Value);
             book.Id            = model.Id;
             book.Author        = model.Author;
             book.Title         = model.Title;
             book.YearPublished = model.Year;
             book.ModifiedDate  = DateTime.UtcNow;
             if (isNew)
             {
                 context.Add(book);
             }
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("Index"));
 }
        public IActionResult AddEditPais(long?id, PaisViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool isNew = !id.HasValue;
                    Pais pais  = isNew ? new Pais
                    {
                    } : context.Set <Pais>().SingleOrDefault(s => s.Id == id.Value);

                    pais.Descricao = model.Descricao;

                    if (isNew)
                    {
                        context.Add(pais);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }
示例#4
0
 public ActionResult AddEditCustomer(long?id, CustomerViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool     isNew    = !id.HasValue;
             Customer customer = isNew ? new Customer
             {
                 AddedDate = DateTime.UtcNow
             } : context.Set <Customer>().SingleOrDefault(s => s.Id == id.Value);
             customer.FirstName    = model.FirstName;
             customer.LastName     = model.LastName;
             customer.MobileNo     = model.MobileNo;
             customer.Email        = model.Email;
             customer.IPAddress    = Request.HttpContext.Connection.RemoteIpAddress.ToString();
             customer.ModifiedDate = DateTime.UtcNow;
             if (isNew)
             {
                 context.Add(customer);
             }
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("Index"));
 }
示例#5
0
 public IActionResult AddEditPaciente(long?id, PacienteViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool     isNew    = !id.HasValue;
             Paciente paciente = isNew ? new Paciente
             {
             } : context.Set <Paciente>().SingleOrDefault(s => s.Id == id.Value);
             paciente.Nome   = model.Nome;
             paciente.CPF    = model.CPF;
             paciente.Pais   = model.Pais;
             paciente.Estado = model.Estado;
             paciente.Cidade = model.Cidade;
             if (isNew)
             {
                 context.Add(paciente);
             }
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("Index"));
 }
示例#6
0
        public IActionResult AddEditEstado(long?id, EstadoViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool   isNew  = !id.HasValue;
                    Estado estado = isNew ? new Estado
                    {
                    } : context.Set <Estado>().SingleOrDefault(s => s.Id == id.Value);

                    estado.Descricao = model.Descricao;
                    estado.Pais      = model.Pais;

                    if (isNew)
                    {
                        context.Add(estado);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }
        public IActionResult AddEditCidade(long?id, CidadeViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool   isNew  = !id.HasValue;
                    Cidade cidade = isNew ? new Cidade
                    {
                    } : context.Set <Cidade>().SingleOrDefault(s => s.Id == id.Value);

                    cidade.Descricao = model.Descricao;
                    cidade.Estado    = model.Estado;

                    if (isNew)
                    {
                        context.Add(cidade);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }
 public IActionResult AddEditBook(long?id, BookViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool isNew = !id.HasValue;
             Book book  = isNew ? new Book
             {
                 AddedDate = DateTime.UtcNow
             } : context.Set <Book>().SingleOrDefault(s => s.Id == id.Value);
             book.Name         = model.Name;
             book.ISBN         = model.ISBN;
             book.Author       = model.Author;
             book.Publisher    = model.Publisher;
             book.IPAddress    = Request.HttpContext.Connection.RemoteIpAddress.ToString();
             book.ModifiedDate = DateTime.UtcNow;
             if (isNew)
             {
                 context.Add(book);
             }
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("Index"));
 }
        public JsonResult Create([FromBody] Customer Customer)


        {
            _context.Add(Customer);
            _context.SaveChanges();
            // return RedirectToAction(nameof(Index));


            return(Json(Customer));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("id,name")] MakeModel makeModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(makeModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(makeModel));
        }
        public async Task <IActionResult> Create([Bind("EmployeeId,Name,Position,Age,Salatry")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,MobileNo")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
示例#13
0
        public JsonResult Create([FromBody] Sale Sale)


        {
            if (ModelState.IsValid)
            {
                _context.Add(Sale);
                _context.SaveChanges();
            }
            return(Json(Sale));
        }
示例#14
0
        public JsonResult Create([FromBody] Product Product)


        {
            if (ModelState.IsValid)
            {
                _context.Add(Product);
                _context.SaveChanges();
            }
            return(Json(Product));
        }
示例#15
0
        public async Task <IActionResult> Create([Bind("id,model,year,cylinders,MakeId")] CarModel carModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MakeId"] = new SelectList(_context.Make, "id", "Name", carModel.MakeId);
            return(View(carModel));
        }
示例#16
0
        public JsonResult Create([FromBody] Sale Sale)


        {
            if (ModelState.IsValid)
            {
                _context.Add(Sale);
                _context.SaveChanges();
                // return RedirectToAction(nameof(Index));
            }
            return(Json(Sale));
        }
示例#17
0
 public IActionResult Create(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("New"));
     }
 }
示例#18
0
 public IActionResult CreateDish(Dish NewDish)
 {
     if (ModelState.IsValid)
     {
         Dish newDish = new Dish()
         {
             Name        = NewDish.Name,
             Chef        = NewDish.Chef,
             Tastiness   = NewDish.Tastiness,
             Calories    = NewDish.Calories,
             Description = NewDish.Description,
         };
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(Redirect("/"));
     }
     else
     {
         return(View("New"));
     }
 }
示例#19
0
 public IActionResult Create(Meal dish)
 {
     if (ModelState.IsValid)
     {
         Meal newDish = new Meal
         {
             Name        = dish.Name,
             Chef        = dish.Chef,
             Tastiness   = dish.Tastiness,
             Calories    = dish.Calories,
             Description = dish.Description
         };
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("New"));
     }
 }
示例#20
0
        public IActionResult createAccount(User newUser)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.users.Any(u => u.Email == newUser.Email))
                {
                    return(View("LoginReg"));
                    // You may consider returning to the View at this point
                }
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                newUser.Password = Hasher.HashPassword(newUser, newUser.Password);
                dbContext.Add(newUser);
                dbContext.SaveChanges();
                HttpContext.Session.SetString("UserName", newUser.Fname);

                return(RedirectToAction("Success"));
            }
            else
            {
                return(View("LoginReg"));
            }
        }
 public IActionResult Create(Dish dish)
 {
     dbContext.Add(dish);
     dbContext.SaveChanges();
     return(RedirectToAction("Index"));
 }