public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductID)
            {
                return(BadRequest());
            }

            db.Entry(product).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IActionResult Authentication([FromBody] Account account)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existStudent = _context.Student.SingleOrDefault(a => a.Email == account.Email);

            if (existStudent == null)
            {
                Response.StatusCode = 403;
                return(new JsonResult("Forbidden1"));
            }

            var isValidPassword = existStudent.CheckLoginPassword(account.Password);

            if (isValidPassword)
            {
                MyCredential credential = new MyCredential(existStudent.Id);
                _context.MyCredentials.Add(credential);
                _context.SaveChanges();
                Response.StatusCode = 200;
                return(new JsonResult(credential));
            }
            Response.StatusCode = 403;
            return(new JsonResult("Forbidden2"));
        }
        public IHttpActionResult PutContacto(int id, Contacto contacto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contacto.SivilaId)
            {
                return(BadRequest());
            }

            db.Entry(contacto).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public ActionResult Create(Models.User user)
        {
            if (ModelState.IsValid)
            {
                //Hash da Senha
                user.Senha          = BCrypt.Net.BCrypt.HashPassword(user.Senha);
                user.ConfirmarSenha = user.Senha;

                //AesCryptoServiceProvider
                AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
                aes.BlockSize = 128;
                aes.KeySize   = 256;
                aes.IV        = Encoding.UTF8.GetBytes(AesIV256BD);
                aes.Key       = Encoding.UTF8.GetBytes(AesKey256BD);
                aes.Mode      = CipherMode.CBC;
                aes.Padding   = PaddingMode.PKCS7;

                byte[] src = Encoding.Unicode.GetBytes(user.Email);

                //Encriptação
                using (ICryptoTransform encrypt = aes.CreateEncryptor())
                {
                    byte[] dest = encrypt.TransformFinalBlock(src, 0, src.Length);

                    //Converte byte array para string de base 64
                    user.Email = Convert.ToBase64String(dest);
                }
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }

            return(View(user));
        }
Ejemplo n.º 5
0
        public Note AddNotes(Note note)
        {
            _dbcontext.Add(note);
            _dbcontext.SaveChanges();

            return(note);
        }
Ejemplo n.º 6
0
        public User UpdateToken(User user)
        {
            var resultUser = GetUser(user.Email);

            resultUser.Token          = user.Token;
            resultUser.TokenExpiresIn = DateTime.Now.AddHours(1);
            _context.SaveChanges();
            return(resultUser);
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "CTUSER_ID,CTUSER_LEVEL,CTUSER_TRANGTHAI")] ChiTietUs chiTietUs)
        {
            if (ModelState.IsValid)
            {
                db.ChiTietUses.Add(chiTietUs);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(chiTietUs));
        }
Ejemplo n.º 8
0
        public ActionResult Create([Bind(Include = "Id,Nome,Cnpj,Email,Telefone")] Fornecedor fornecedor)
        {
            if (ModelState.IsValid)
            {
                db.Fornecedors.Add(fornecedor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fornecedor));
        }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "Id,Nome,Descricao,CorProduto,StatusProduto,IdFornecedor")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                db.Produtos.Add(produto);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdFornecedor = new SelectList(db.Fornecedors, "Id", "Nome", produto.IdFornecedor);
            return(View(produto));
        }
Ejemplo n.º 10
0
 public bool Create(Author author)
 {
     try
     {
         _context.Authors.Add(author);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 11
0
 public bool Create(Book book)
 {
     try
     {
         _context.Books.Add(book);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "CSCT_ID,CSCT_TenThuoc,CSCT_SoLuong,CSCT_Ngay,CS_ID,CSCT_TongTien")] ChamSocChiTiet chamSocChiTiet)
        {
            if (ModelState.IsValid)
            {
                chamSocChiTiet.CSCT_ID = autotang(db.ChamSocChiTiets.Count());
                chamSocChiTiet.CS_ID   = Convert.ToInt32(Session["CS_ID"]);
                db.ChamSocChiTiets.Add(chamSocChiTiet);
                db.SaveChanges();
                return(RedirectToAction("Index/" + Session["CS_ID"]));
            }

            ViewBag.CS_ID = new SelectList(db.ChamSocs, "CS_ID", "CS_Name", chamSocChiTiet.CS_ID);
            return(View(chamSocChiTiet));
        }
Ejemplo n.º 13
0
        public ActionResult Create([Bind(Include = "Ruong_ID,User_ID,Ruong_Name,Ruong_DienTich,Ruong_MoTa")] Ruong ruong)
        {
            if (ModelState.IsValid)
            {
                ruong.Ruong_ID = autotang(db.Ruongs.Count());
                ruong.User_ID  = Convert.ToInt32(Session["User_ID"]);
                db.Ruongs.Add(ruong);
                db.SaveChanges();
                return(RedirectToAction("Index/" + Session["User_ID"]));
            }

            ViewBag.User_ID = new SelectList(db.Users, "User_ID", "User_Name", ruong.User_ID);
            return(View(ruong));
        }
Ejemplo n.º 14
0
        public ActionResult Create([Bind(Include = "CS_ID,Ruong_ID,CS_Name,CS_MoTa,CS_Mua")] ChamSoc chamSoc)
        {
            if (ModelState.IsValid)
            {
                chamSoc.CS_ID    = autotang(db.ChamSocs.Count());
                chamSoc.Ruong_ID = Convert.ToInt32(Session["Ruong_ID"]);
                db.ChamSocs.Add(chamSoc);
                db.SaveChanges();
                return(RedirectToAction("Index/" + Session["Ruong_ID"]));
            }

            ViewBag.Ruong_ID = new SelectList(db.Ruongs, "Ruong_ID", "Ruong_Name", chamSoc.Ruong_ID);
            return(View(chamSoc));
        }
Ejemplo n.º 15
0
        public ActionResult DeclineFriend(int id)
        {
            var requester   = id;
            var currentUser = Convert.ToInt32(Session["UserID"]);

            using (Datacontext db = new Datacontext())
            {
                var AllFriendConnections = db.Friends.ToList();
                var PendingFriends       = new List <Friend>();
                foreach (Friend friend in AllFriendConnections)
                {
                    if (friend.Accepted == false)
                    {
                        PendingFriends.Add(friend);
                    }
                }
                foreach (Friend friend in PendingFriends)
                {
                    if (friend.Friend1 == id && friend.Friend2 == currentUser)
                    {
                        db.Friends.Remove(friend);
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("Friends"));
            }
        }
        public ActionResult EditProfilePic(editwrapper edit)
        {
            try
            {
                using (Datacontext db = new Datacontext())
                {
                    var id  = int.Parse(Session["UserID"].ToString());
                    var usr = db.Users.Single(u => u.Id == id);
                    if ((edit.ProfileURL.ProfileURL.EndsWith(".jpg") || edit.ProfileURL.ProfileURL.EndsWith(".png") || edit.ProfileURL.ProfileURL.EndsWith(".img")) && edit.ProfileURL.ProfileURL != null)
                    {
                        usr.PictureURL = edit.ProfileURL.ProfileURL;
                    }
                    else
                    {
                        ModelState.AddModelError("", "Must be a URL from the internet ending with .jpg, .png or .img");
                    }



                    db.SaveChanges();
                }
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong, please try again.");
                return(View("EditAccount"));
            }
            return(RedirectToAction("EditAccount"));
        }
Ejemplo n.º 17
0
 public void insertPost([FromBody] Posts newPost)
 {
     if (newPost.TextContent != "")
     {
         db.Post.Add(newPost);
         db.SaveChanges();
     }
 }
Ejemplo n.º 18
0
        public ActionResult Create([Bind(Include = "TH_ID,Ruong_ID,TH_Name,TH_ChiSo,TH_TienTrenDa,TH_TongTien,TH_MoTa")] ThuHoach thuHoach)
        {
            int SoDa       = Convert.ToInt32(Request["TH_ChiSo"]);
            int tientrenda = Convert.ToInt32(Request["TH_TienTrenDa"]);

            if (ModelState.IsValid)
            {
                thuHoach.TH_ID       = autotang(db.ThuHoaches.Count());
                thuHoach.Ruong_ID    = Convert.ToInt32(Session["Ruong_ID"]);
                thuHoach.TH_TongTien = SoDa * tientrenda;
                db.ThuHoaches.Add(thuHoach);
                db.SaveChanges();
                return(RedirectToAction("Index/" + Session["Ruong_ID"]));
            }

            ViewBag.Ruong_ID = new SelectList(db.Ruongs, "Ruong_ID", "Ruong_Name", thuHoach.Ruong_ID);
            return(View(thuHoach));
        }
Ejemplo n.º 19
0
        public ActionResult Create([Bind(Include = "User_ID,CTUSER_ID,User_Name,User_Detail,User_TK,User_MK")] User user)
        {
            string TK       = Request["User_TK"];
            string MK       = Request["User_MK"];
            string MK1      = Request["User_MK1"];
            string UserName = Request["User_Name"];
            string TenTK    = db.Database.SqlQuery <string>("select User_TK from Users where User_TK ='" + TK + "'").SingleOrDefault();

            if (UserName.Length <= 0)
            {
                ModelState.AddModelError("", "Tên người dùng không được để trống");
            }
            else if (TK.Length <= 0)
            {
                ModelState.AddModelError("", "Tài khoản không được để trống");
            }
            if (TenTK != null)
            {
                ModelState.AddModelError("", "Tài khoản đã tồn tại");
            }
            else

            if (MK.Length == 0 || MK1.Length == 0)
            {
                ModelState.AddModelError("", "Mật khẩu không được để trống");
            }
            else if (MK != MK1)
            {
                ModelState.AddModelError("", "Mật khẩu xác nhận không giống nhau !@!");
            }
            if (ModelState.IsValid)
            {
                user.User_ID   = autotang(db.Users.Count());
                user.CTUSER_ID = 1;
                user.User_MK   = PassMD5.GetMD5(MK);
                db.Users.Add(user);
                db.SaveChanges();
                ModelState.AddModelError("", "Đăng ký thành công !!!");
            }

            ViewBag.CTUSER_ID = new SelectList(db.ChiTietUses, "CTUSER_ID", "CTUSER_ID", user.CTUSER_ID);
            return(View(user));
        }
Ejemplo n.º 20
0
        public void AddReview(Review review, double average, int amount)
        {
            _db.Reviews.Add(review);
            var book = (from b in _db.Books
                        where b.BookId == review.BookId
                        select b).SingleOrDefault();

            book.ReviewScore = Math.Round((review.Rating + average * amount) / (amount + 1), 2);
            _db.SaveChanges();
        }
Ejemplo n.º 21
0
 public StudentsController(Datacontext datacontext)
 {
     _datacontext = datacontext;
     if (_datacontext.Students.Count() == 0)
     {
         _datacontext.Students.Add(new Student {
             Name = "Huy", ClassId = 1, Address = "Ha Dong", Email = "*****@*****.**"
         });
         _datacontext.SaveChanges();
     }
 }
Ejemplo n.º 22
0
 public ClassesController(Datacontext datacontext)
 {
     _datacontext = datacontext;
     if (_datacontext.Classes.Count() == 0)
     {
         _datacontext.Classes.Add(new Class {
             Name = "AT12"
         });
         _datacontext.SaveChanges();
     }
 }
Ejemplo n.º 23
0
        public static void SeedData()
        {
            var db = new Datacontext();

            if (!db.Books.Any())
            {
                var InitialBooks = new List <Book>()
                {
                    //10 default books, Sindri
                    new Book
                    {
                        Title = "The Hitchhiker's Guide to the Galaxy", Author = "Douglas Adams", ReleaseYear = 1979, Genre = "SciFi", ISBN = "330258648", Price = 17.99, Stock = 10, TopSeller = false, OnSale = false, Discount = 0, Image = "https://images.penguinrandomhouse.com/cover/9781400052929"
                    },
                    new Book
                    {
                        Title = "It", Author = "Stephen King", ReleaseYear = 1986, Genre = "Horror", ISBN = "670813028", Price = 23.99, Stock = 15, TopSeller = false, OnSale = false, Discount = 0, Image = "http://cdn.collider.com/wp-content/uploads/2017/09/it-book-cover.jpg"
                    },
                    new Book
                    {
                        Title = "The Dark Knight Returns", Author = "Frank Miller", ReleaseYear = 1986, Genre = "Comics", ISBN = "1563893428", Price = 20.99, Stock = 25, TopSeller = false, OnSale = false, Discount = 0, Image = "https://upload.wikimedia.org/wikipedia/en/7/77/Dark_knight_returns.jpg"
                    },
                    new Book
                    {
                        Title = "The Shining", Author = "Stephen King", ReleaseYear = 1977, Genre = "Horror", ISBN = "9780385121675", Price = 10.99, Stock = 20, TopSeller = false, OnSale = false, Discount = 0, Image = "https://upload.wikimedia.org/wikipedia/en/4/4c/Shiningnovel.jpg"
                    },
                    new Book
                    {
                        Title = "Stars in My Pocket Like Grains of Sand", Author = "Samuel R. Delany", ReleaseYear = 1984, Genre = "SciFi", ISBN = "9780553050530", Price = 27.99, Stock = 10, TopSeller = false, OnSale = false, Discount = 0, Image = "https://upload.wikimedia.org/wikipedia/en/4/4d/Stars_in_my_pocket_like_grains_of_sand.jpg"
                    },
                    new Book
                    {
                        Title = "The Grapes of Wrath", Author = "John Steinbeck", ReleaseYear = 1939, Genre = "Drama", ISBN = "9780143039433", Price = 11.49, Stock = 7, TopSeller = false, OnSale = false, Discount = 0, Image = "https://upload.wikimedia.org/wikipedia/en/1/1f/JohnSteinbeck_TheGrapesOfWrath.jpg"
                    },
                    new Book
                    {
                        Title = "How to Compile C Code", Author = "Bjorgvin Karason", ReleaseYear = 2013, Genre = "Educational", ISBN = "9780446310001", Price = 44.29, Stock = 13, TopSeller = false, OnSale = false, Discount = 0, Image = "https://images-na.ssl-images-amazon.com/images/I/41gpxHEh2rL._SX403_BO1,204,203,200_.jpg"
                    },
                    new Book
                    {
                        Title = "The Hobbit, or There and Back Again", Author = "J. R. R. Tolkien", ReleaseYear = 1937, Genre = "Fantasy", ISBN = "9780547928227", Price = 27.09, Stock = 50, TopSeller = false, OnSale = false, Discount = 0, Image = "http://media.bookbub.com/wp-content/uploads/2014/12/1937.jpg"
                    },
                    new Book
                    {
                        Title = "To Kill a Mockingbird", Author = "Harper Lee", ReleaseYear = 1960, Genre = "Drama", ISBN = "9780446310789", Price = 23.99, Stock = 15, TopSeller = false, OnSale = false, Discount = 0, Image = "https://upload.wikimedia.org/wikipedia/en/7/79/To_Kill_a_Mockingbird.JPG"
                    },
                    new Book
                    {
                        Title = "Foundation", Author = "Isaac Asimov", ReleaseYear = 1951, Genre = "SciFi", ISBN = "553293354", Price = 25.99, Stock = 30, TopSeller = false, OnSale = false, Discount = 0, Image = "https://static.squarespace.com/static/51b3dc8ee4b051b96ceb10de/51ce6099e4b0d911b4489b79/51ce6178e4b0d911b4495446/1317432124153/1000w/Isaac%20Asimov_1951_Foundation.jpg"
                    }
                };
                db.AddRange(InitialBooks);
                db.SaveChanges();
            }
        }
Ejemplo n.º 24
0
        public void AddToCart(Book book, string ShoppingCartId)
        {
            var cartItem = _storeDb.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId &&
                c.BookId == book.BookId);

            if (cartItem == null)
            {
                //no items in cart
                cartItem = new Cart
                {
                    CartId      = ShoppingCartId,
                    BookId      = book.BookId,
                    Count       = 1,
                    DateCreated = DateTime.Now,
                };
                _storeDb.Carts.Add(cartItem);
            }
            else
            {
                //if the book exists in the cart, increase the quantity
                cartItem.Count++;
            }
            _storeDb.SaveChanges();
        }
Ejemplo n.º 25
0
 public ActionResult AddFriend(int id)
 {
     using (Datacontext db = new Datacontext())
     {
         Friend friend = new Friend();
         friend.Friend1  = Convert.ToInt32(Session["UserID"]);
         friend.Friend2  = id;
         friend.Accepted = false;
         db.Friends.Add(friend);
         db.SaveChanges();
         return(RedirectToAction("FriendProfile", new { id = id }));
     }
 }
Ejemplo n.º 26
0
        public IActionResult Register(User user)
        {
            Data_User datauser = new Data_User();

            datauser.UserId   = user.UserId;
            datauser.UserName = user.UserName;
            datauser.Password = user.Password;


            _datacontext.data_Users.Add(datauser);
            _datacontext.SaveChanges();

            return(Content("Registration Successful , Please Login"));
        }
Ejemplo n.º 27
0
        public IActionResult Post(string type, Light model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (type == "light")
            {
                var rec = new Light();

                rec.Status = model.Status;

                _db.Lights.Add(rec);
                _db.SaveChanges();

                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 28
0
      public IActionResult Create([FromBody] User data)
      {
          var user = _context.Users.SingleOrDefault(x => x.UserName == data.UserName);

          if (user != null)
          {
              return(Ok(
                         new{ success = "This Username Already used" }
                         ));
          }
          _context.Users.Add(data);
          _context.SaveChanges();

          return(Ok(
                     new{ success = "true" }
                     ));
      }
Ejemplo n.º 29
0
        public ActionResult Save(Customer customer)
        {
            if (customer.Id == 0)
            {
                _context.Customers.Add(customer);
            }
            else
            {
                var customerInDb = _context.Customers.Single(c => c.Id == customer.Id);

                customerInDb.Name                     = customer.Name;
                customerInDb.BirthDate                = customer.BirthDate;
                customerInDb.MemberShipTypeId         = customer.MemberShipTypeId;
                customerInDb.IsSubscribedToNewsLetter = customer.IsSubscribedToNewsLetter;
            }
            _context.SaveChanges();

            return(RedirectToAction("CustomerDetails", "Customers"));
        }
        public ActionResult EditAbout(editwrapper edit)
        {
            try
            {
                using (Datacontext db = new Datacontext())
                {
                    var id  = int.Parse(Session["UserID"].ToString());
                    var usr = db.Users.Single(u => u.Id == id);
                    usr.About = edit.About.About;

                    db.SaveChanges();
                }
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong, please try again.");
                return(View("EditAccount"));
            }
            return(RedirectToAction("EditAccount"));
        }