コード例 #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));
        }
コード例 #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"));
        }
コード例 #3
0
 public IActionResult AddEmployee(Employee emp)
 {
     if (!ModelState.IsValid)
     {
         return(View(emp));
     }
     context.Add(emp);
     context.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #4
0
 public IActionResult Create(Employee model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     context.Add(model);
     context.SaveChanges();
     return(RedirectToAction("index"));
 }
コード例 #5
0
        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));
        }
コード例 #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));
        }
コード例 #7
0
        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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #10
0
        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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #17
0
        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));
        }
コード例 #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");
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #28
0
ファイル: SongController.cs プロジェクト: mhtsbt/MusicMix
        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));
        }
コード例 #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();
        }
コード例 #30
0
 public void Create(T entity)
 {
     _context.Add(entity);
     Save();
 }