public IActionResult Create(IFormCollection data)
 {
     try
     {
         var      info = HttpContext.Session.GetObject <LoginInfo>("Info");
         Employee emp  = new Employee();
         emp.LastName    = data["lastName"];
         emp.FirstName   = data["firstName"];
         emp.UserName    = data["userName"];
         emp.Password    = MD5Hash(data["password"]);
         emp.Address     = data["address"];
         emp.Email       = data["email"];
         emp.Phone       = data["phone"];
         emp.BirthDate   = DateTime.Parse(data["birthday"]);
         emp.Role        = int.Parse(data["role"]);
         emp.ManagerId   = int.Parse(data["managerId"]);
         emp.Status      = int.Parse(data["status"]);
         emp.CreatedDate = DateTime.Now;
         emp.CreatedBy   = info.UserID;
         _ctx.Employee.Add(emp);
         _ctx.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(BadRequest());
     }
 }
Beispiel #2
0
        //[Route("Admin/Product/{id}")]
        public IActionResult Update(int id, IFormCollection data)
        {
            var product = _ctx.Product.SingleOrDefault(p => p.ProductId == id);


            product.ProductName    = data["productName"];
            product.CategoryId     = int.Parse(data["categoryID"]);
            product.Quantity       = int.Parse(data["quantity"]);
            product.Price          = int.Parse(data["price"]);
            product.PromotionPrice = int.Parse(data["promotionPrice"]);
            product.Description    = data["description"];
            product.ModifiedDate   = DateTime.Now;
            product.Status         = int.Parse(data["status"]);
            product.IncludeVat     = data["IncludeVat"] == 1?true:false;
            if (data["image"].Count() == 0)
            {
                product.ProductImage = data["image"];
            }
            try
            {
                _ctx.Product.Update(product);
                _ctx.SaveChanges();
                //  Success
                Response.StatusCode = (int)HttpStatusCode.OK;
                return(RedirectToAction("Index"));
            }
            catch
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            return(Content("Fail!"));
        }
        public IActionResult Index(UserProfileView userProfile)
        {
            if (ModelState.IsValid)
            {
                LoginInfo info = HttpContext.Session.GetObject <LoginInfo>("Info");
                switch (info.position)
                {
                case "nv":
                {
                    var nv = _ctx.Employee.Where(p => p.EmployeeId == info.UserID).SingleOrDefault();
                    if (nv != null)
                    {
                        nv.FirstName = userProfile.FirstName;
                        nv.LastName  = userProfile.LastName;
                        nv.Email     = userProfile.Email;
                        nv.Address   = userProfile.Address;
                        nv.Phone     = userProfile.Phone;
                        _ctx.Employee.Update(nv);
                        _ctx.SaveChanges();
                    }
                    break;
                }

                case "kh":
                {
                    var cus = _ctx.Customer.Where(p => p.CustomerId == info.UserID).SingleOrDefault();
                    if (cus != null)
                    {
                        cus.FirstName = userProfile.FirstName;
                        cus.LastName  = userProfile.LastName;
                        cus.Email     = userProfile.Email;
                        cus.Address   = userProfile.Address;
                        cus.Phone     = userProfile.Phone;
                        _ctx.Customer.Update(cus);
                        _ctx.SaveChanges();
                    }
                    break;
                }
                }
                info.Name = userProfile.FirstName + " " + userProfile.LastName;
                HttpContext.Session.SetObject <LoginInfo>("Info", info);
            }
            userProfile.orders = list;
            return(View(userProfile));
        }
Beispiel #4
0
        public async void ShouldGetAllRestaurants()
        {
            var options = new DbContextOptionsBuilder <OrderFoodContext>().UseInMemoryDatabase(databaseName: "ShouldGetAllRestaurants").Options;

            var sortedList = new List <Restaurant>()
            {
                new Restaurant()
                {
                    Name = "Ramzes", Website = "www.ramzes.pl"
                },
                new Restaurant()
                {
                    Name = "Kebab Hot", Website = "www.kebabhot.pl"
                },
                new Restaurant()
                {
                    Name = "Muzyczna", Website = "www.muzyczna.pl"
                }
            };


            using (var context = new OrderFoodContext(options))
            {
                foreach (var game in sortedList)
                {
                    context.Add(game);
                    context.SaveChanges();
                }
            }

            // Act
            IEnumerable <Restaurant> actualList;

            using (var context = new OrderFoodContext(options))
            {
                var repository = new RestaurantRepository(context);
                actualList = await repository.GetAll();
            }

            // Assert
            Assert.Equal(sortedList.Count(), actualList.Count());
        }