Ejemplo n.º 1
0
        public async Task <IActionResult> Create(TaxiEntity taxiEntity)
        {
            if (ModelState.IsValid)
            {
                taxiEntity.Plaque = taxiEntity.Plaque.ToUpper();
                _context.Add(taxiEntity);

                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "Already exist a Taxi with the same Plaque.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }
            return(View(taxiEntity));
        }
Ejemplo n.º 2
0
        public IActionResult Register()
        {
            var    valid    = true;
            string fullName = HttpContext.Request.Form["fullName"];
            string email    = HttpContext.Request.Form["email"];
            string password = HttpContext.Request.Form["password"];

            if (fullName.Length < 6 || email.Length < 6 || password.Length < 6 ||
                fullName.Length > 30 || email.Length > 30 || password.Length > 30)
            {
                valid = false;
            }
            if (valid)
            {
                UserDetails user = new UserDetails
                {
                    Name     = fullName,
                    Email    = email,
                    Password = password,
                };
                _context.Add(user);
                _context.SaveChangesAsync();
            }
            else
            {
                ViewData["message"] = "Username, Password Invalid.";
                return(View("Login-Register"));
            }
            return(RedirectToAction("Index", "Home"));
        }
 public IActionResult AddEmployee(Employee emp)
 {
     if (!ModelState.IsValid)
     {
         return(View(emp));
     }
     context.Add(emp);
     context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 4
0
 public IActionResult Create(Employee model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     context.Add(model);
     context.SaveChanges();
     return(RedirectToAction("index"));
 }
        public async Task <IActionResult> Create([Bind("CardID,type")] DiscountCard discountCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(discountCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(discountCard));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Ten")] TheLoai theLoai)
        {
            if (ModelState.IsValid)
            {
                _context.Add(theLoai);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(theLoai));
        }
        public async Task <IActionResult> Create([Bind("categoryID,categoryName,Quantity")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Email,MatKhau,DiaChi")] NguoiDung nguoiDung)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nguoiDung);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nguoiDung));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("AlunoId,Nome,Email,RA,DataCadastro")] Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aluno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
        public async Task <IActionResult> Create([Bind("Id,Nome,Valor")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(produto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(produto));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("id,name")] RequestCategory requestCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(requestCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(requestCategory));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("BlocoId,Nome,Descricao")] Bloco bloco)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bloco);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bloco));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("Id,Ip,Name,Age")] info info)
        {
            if (ModelState.IsValid)
            {
                _context.Add(info);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(info));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Ten,CauTraLoi1,CauTraLoi2,CauTraLoi3,CauTraLoi4,TheLoaiId")] CauHoi cauHoi)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cauHoi);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TheLoaiId"] = new SelectList(_context.TheLoais, "Id", "Id", cauHoi.TheLoaiId);
            return(View(cauHoi));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Create([Bind("Id,Ten,CauHoiThiId,NguoiDungId")] Thi thi)
        {
            if (ModelState.IsValid)
            {
                _context.Add(thi);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["NguoiDungId"] = new SelectList(_context.NguoiDungs, "Id", "DiaChi", thi.NguoiDungId);
            return(View(thi));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Create([Bind("Id,Ten,CauHoiId")] DapAn dapAn)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dapAn);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CauHoiId"] = new SelectList(_context.CauHoi, "Id", "Id", dapAn.CauHoiId);
            return(View(dapAn));
        }
        public async Task <IActionResult> Create([Bind("productID,Name,Price,Image,productDate,categoryID")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["categoryID"] = new SelectList(_context.Items, "categoryID", "categoryName", product.categoryID);
            return(View(product));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> AddTodo([FromBody] Todo todo)
        {
            todo.CreatedOn = DateTime.Now;
            _context.Add(todo);

            if (await _context.SaveChangesAsync() > 0)
            {
                return(CreatedAtRoute(new { isSaved = true }, "Your todo is Successfully added"));
            }

            throw new Exception("Creating todo failed on save");
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create([Bind("userID,FullName,DateOfBirth,cardID")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["cardID"] = new SelectList(_context.Cards, "CardID", "type", user.cardID);
            return(View(user));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Create([Bind("Id,Ten,ThiId")] Diem diem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ThiId"] = new SelectList(_context.This, "Id", "Ten", diem.ThiId);
            return(View(diem));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Create([Bind("SalaId,Nome,BlocoId,Disponivel")] Sala sala)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sala);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BlocoId"] = new SelectList(_context.Bloco, "BlocoId", "BlocoId", sala.BlocoId);
            return(View(sala));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Create([Bind("userID,AddressLine1,City,State,Country")] Address address)
        {
            if (ModelState.IsValid)
            {
                _context.Add(address);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["userID"] = new SelectList(_context.Users, "userID", "FullName", address.userID);
            return(View(address));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Create([Bind("ID,userID,productID")] Basket basket)
        {
            if (ModelState.IsValid)
            {
                _context.Add(basket);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["productID"] = new SelectList(_context.Products, "productID", "Name", basket.productID);
            ViewData["userID"]    = new SelectList(_context.Users, "userID", "FullName", basket.userID);
            return(View(basket));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Create([Bind("ReservaId,Nome,SalaId,DataInicio,DataFim,AlunoId")] Models.Reserva reserva)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reserva);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AlunoId"] = new SelectList(_context.Aluno, "AlunoId", "AlunoId", reserva.AlunoId);
            ViewData["SalaId"]  = new SelectList(_context.Sala, "SalaId", "SalaId", reserva.SalaId);
            return(View(reserva));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Create([Bind("CauHoiId,ThiId,Ten")] CauHoiThi cauHoiThi)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cauHoiThi);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CauHoiId"] = new SelectList(_context.CauHoi, "Id", "Ten");
            ViewData["ThiId"]    = new SelectList(_context.This, "Id", "Ten");
            return(View(cauHoiThi));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Create([Bind("id,name,contactNumber,category,text,date,status,operatorName")] Request request)
        {
            if (ModelState.IsValid)
            {
                request.date         = DateTime.Now;
                request.status       = "Зарегистрировано";
                request.operatorName = CurrentUser.Name;
                _context.Add(request);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(request));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Create([Bind("id,username,passwordHash,salt,role")] User user)
        {
            if (ModelState.IsValid)
            {
                string salt = Cryptography.GenerateSalt();
                user.salt         = salt;
                user.passwordHash = Cryptography.GetHash(user.passwordHash + salt);
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(user));
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> Create([Bind("Id,Title,Artist,FileName,StartTime,StopTime")] Song song)
        {
            if (ModelState.IsValid)
            {
                _context.Add(song);
                await _context.SaveChangesAsync();

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

            song.Position = _context.Songs.Count();

            return(View(song));
        }
Ejemplo n.º 29
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new Exception($"Request with {id} already exists") :
                                new IdempotencyTransactionLog()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.UtcNow
                                };

            _context.Add(request);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 30
0
 public void Create(T entity)
 {
     _context.Add(entity);
     Save();
 }