public ActionResult Register(Customer cus, HttpPostedFileBase image)
        {
            cus.CustomerID = Guid.NewGuid();
            cus.UserType   = "web";

            if (image != null)
            {
                FileData fileData = new FileData();
                //attach the uploaded image to the object before saving to Database
                fileData.FileType = image.ContentType;
                image.InputStream.Read(new byte[image.ContentLength], 0, image.ContentLength);

                //Save image to file
                var    filename          = image.FileName;
                var    filePathOriginal  = Server.MapPath("/Data/Originals");
                var    filePathThumbnail = Server.MapPath("/Data/Thumbnails");
                string savedFileName     = Path.Combine(filePathOriginal, filename);
                image.SaveAs(savedFileName);
                fileData.FileName = filename;
                fileData.URL      = "/Data/Originals/" + filename;
                db.FileDatas.Add(fileData);
                db.SaveChanges();

                cus.FileID = fileData.FileID;
            }
            db.Customers.Add(cus);
            db.SaveChanges();
            ModelState.Clear();
            ViewBag.Message = cus.FullName + "đăng kí thành công";
            return(View());
        }
Beispiel #2
0
 public ActionResult ThemDanhMuc(Category category, string StoreID)
 {
     category.CategoryID = Guid.NewGuid();
     category.StoreID    = Guid.Parse(StoreID);
     if (ModelState.IsValid)
     {
         //Thực hiện cập nhận trong model
         db.Entry(category).State = System.Data.Entity.EntityState.Added;
         db.SaveChanges();
         Session["Message"] = category.CategoryName + " thêm thành công";
         return(RedirectToAction("QuanLyDanhMucMonAn", new { StoreID = StoreID, page = 1, method = "ThemMoi" }));
     }
     ViewBag.StoreID = StoreID;
     return(View(category));
 }
Beispiel #3
0
 public ActionResult Register(Customer cus, HttpPostedFileBase fileUpload)
 {
     cus.CustomerID = Guid.NewGuid();
     db.Customers.Add(cus);
     db.SaveChanges();
     ModelState.Clear();
     ViewBag.Message = cus.FullName + "đăng kí thành công";
     return(View());
 }
 public JsonResult createBinhluan(BinhLuanEntity binhluan)
 {
     if (binhluan != null && Session["FullName"] != null)
     {
         try
         {
             Customer cus  = (Customer)Session["TaiKhoan"];
             Post     post = new Post
             {
                 Title      = binhluan.Title,
                 Content    = binhluan.Content,
                 Rating     = binhluan.Rating,
                 StoreID    = Guid.Parse(binhluan.StoreID),
                 CustomerID = cus.CustomerID,
                 Like       = 0,
                 View       = 0,
                 PostTime   = DateTime.Now,
                 Status     = 0,
                 Hide       = 0
             };
             if (ModelState.IsValid)
             {
                 db.Entry(post).State = System.Data.Entity.EntityState.Added;
                 db.SaveChanges();
             }
             foreach (var file in binhluan.ListFileUpload)
             {
                 FileData fileData = saveBase64FileData(file.dataImage, file.fileName, file.fileSize, file.fileType);
                 if (fileData != null)
                 {
                     PostImage postImage = new PostImage
                     {
                         PostID = post.PostID,
                         FileID = fileData.FileID,
                         URL    = fileData.URL
                     };
                     db.Entry(postImage).State = System.Data.Entity.EntityState.Added;
                     db.SaveChanges();
                 }
             }
             return(Json(true));
         }
         catch
         {
             return(Json(false));
         }
     }
     return(Json(false));
 }
 public ActionResult ThemMonAn(Food food, string StoreID)
 {
     food.FoodID  = Guid.NewGuid();
     food.StoreID = Guid.Parse(StoreID);
     if (ModelState.IsValid)
     {
         //Thực hiện cập nhận trong model
         db.Entry(food).State = System.Data.Entity.EntityState.Added;
         db.SaveChanges();
         Session["Message"] = food.FoodName + " thêm thành công";
         return(RedirectToAction("QuanLyMonAn", new { StoreID = StoreID, page = 1, method = "ThemMoi" }));
     }
     ViewBag.CategoryID = new SelectList(db.Categories.Where(n => n.StoreID == food.StoreID)
                                         .OrderBy(n => n.CategoryName).ToList(), "CategoryID", "CategoryName", food.CategoryID);
     ViewBag.StoreID = StoreID;
     return(View(food));
 }
Beispiel #6
0
        public ActionResult Edit(Food food, Guid StoreID)
        {
            var f = db.Foods.Where(n => n.FoodID == food.FoodID).SingleOrDefault();

            if (f == null)
            {
                //Trả về trang báo lỗi
                Response.StatusCode = 404;
                return(null);
            }
            f.StoreID = StoreID;
            if (ModelState.IsValid)
            {
                //Thực hiện cập nhận trong model
                db.Entry(f).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            ViewBag.Message = f.FoodName + " Cập nhật thành công";
            ViewBag.StoreID = StoreID;
            return(View(food));
        }
        public ActionResult ThongTin(Store store, HttpPostedFileBase image)
        {
            Store st = db.Stores.Where(n => n.StoreID == store.StoreID).SingleOrDefault();

            if (st == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            if (image != null)
            {
                FileData fileData = new FileData();
                //attach the uploaded image to the object before saving to Database
                fileData.FileType = image.ContentType;
                image.InputStream.Read(new byte[image.ContentLength], 0, image.ContentLength);

                //Save image to file
                var    filename          = image.FileName;
                var    filePathOriginal  = Server.MapPath("/Data/Originals");
                var    filePathThumbnail = Server.MapPath("/Data/Thumbnails");
                string savedFileName     = Path.Combine(filePathOriginal, filename);
                image.SaveAs(savedFileName);
                fileData.FileName = filename;
                fileData.URL      = "/Data/Originals/" + filename;
                db.FileDatas.Add(fileData);
                db.SaveChanges();
                st.FileID = fileData.FileID;
            }
            st.StoreName     = store.StoreName;
            st.Address       = store.Address;
            st.OpenDoor      = store.OpenDoor;
            st.CloserDoor    = store.CloserDoor;
            st.ServiceCharge = store.ServiceCharge;
            st.ShippingFee   = store.ShippingFee;
            st.Manner        = store.Manner;
            st.Website       = store.Website;
            st.StoreType     = store.StoreType;
            st.StoreBanner   = store.StoreBanner;
            st.StartDate     = store.StartDate;
            st.EndDate       = store.EndDate;
            st.Rating        = 0;
            st.Evaluation    = 0;
            st.ConditionShip = store.ConditionShip;
            if (ModelState.IsValid)
            {
                //Thực hiện cập nhận trong model
                db.Entry(st).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                ViewBag.Message = store.StoreName + " Cập nhật thành công";
            }
            ViewBag.StoreID = store.StoreID;
            return(View(store));
        }
        public ActionResult SuaTTHoaDon(string InvoiceID, int status, string StoreID)
        {
            var ivID = Guid.Parse(InvoiceID);
            var f    = db.Invoices.Where(n => n.InvoiceID == ivID).SingleOrDefault();

            if (f == null)
            {
                //Trả về trang báo lỗi
                Response.StatusCode = 404;
                return(null);
            }
            f.Status = status;
            if (ModelState.IsValid)
            {
                //Thực hiện cập nhận trong model
                db.Entry(f).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                Session["Message"] = f.InvoiceID + " cập nhật thành công";
                return(RedirectToAction("QuanLyHoaDon", "Invoice", new { StoreID = StoreID, page = 1, method = "Sua" }));
            }
            Session["Message"] = f.InvoiceID + " cập nhật thất bại";
            return(RedirectToAction("QuanLyHoaDon", "Invoice", new { StoreID = StoreID, page = 1, method = "Sua" }));
        }
Beispiel #9
0
        public ActionResult ThongTin(Store store)
        {
            Store st = db.Stores.Where(n => n.StoreID == store.StoreID).SingleOrDefault();

            if (st == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            st.CustomerID = Guid.Parse(Session["CustomerID"].ToString());
            if (ModelState.IsValid)
            {
                //Thực hiện cập nhận trong model
                db.Entry(st).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            ViewBag.Message = store.StoreName + "Cập nhật thành công";
            return(View(st));
        }
 public JsonResult SuaSTTStore(string StoreID, int Status)
 {
     try
     {
         var stID = Guid.Parse(StoreID);
         var st   = db.Stores.Where(n => n.StoreID == stID).SingleOrDefault();
         if (st == null)
         {
             //Trả về trang báo lỗi
             Response.StatusCode = 404;
             return(null);
         }
         st.Status = Status;
         //Thực hiện cập nhận trong model
         db.Entry(st).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(Json(true));
     }
     catch
     {
         return(Json(false));
     }
 }
        public JsonResult DatHang(DatHangDto datHangDto)
        {
            if (Session["TaiKhoan"] != null)
            {
                try
                {
                    Customer       cus          = (Customer)Session["TaiKhoan"];
                    var            stID         = Guid.Parse(datHangDto.StoreID);
                    Store          store        = db.Stores.Where(n => n.StoreID == stID).SingleOrDefault();
                    GioHangStore   gioHangStore = getGioHangStore(stID + "");
                    List <GioHang> lstGioHang   = new List <GioHang>();
                    if (store != null && gioHangStore.Orders != null)
                    {
                        lstGioHang = gioHangStore.Orders;
                        var tongCong = 0;
                        lstGioHang.ForEach(n => tongCong += (int)n.ThanhTien);
                        var totalPrice    = tongCong;
                        var serviceChange = 0;
                        if (tongCong < store.ConditionShip)
                        {
                            totalPrice   += (int)store.ServiceCharge;
                            serviceChange = (int)store.ServiceCharge;
                        }
                        var sale = 0;
                        if (datHangDto.StoreSaleID != 0)
                        {
                            StoreSale stSale = db.StoreSales.Where(n => n.StoreSaleID == datHangDto.StoreSaleID && n.StoreID == store.StoreID).SingleOrDefault();
                            if (stSale != null)
                            {
                                sale       = totalPrice * (int)stSale.Sale / 100;
                                totalPrice = totalPrice - sale;
                            }
                        }
                        var shippingFee = 0;
                        if (datHangDto.Distance > 0)
                        {
                            shippingFee = (int)(datHangDto.Distance * store.ShippingFee);
                        }
                        lstGioHang = gioHangStore.Orders;
                        Invoice iv = new Invoice()
                        {
                            InvoiceID       = Guid.NewGuid(),
                            OrderDate       = DateTime.Now,
                            DeliveryDate    = DateTime.Parse(datHangDto.DateDelivery + " " + datHangDto.TimeDelivery),
                            AddressDelivery = datHangDto.CustomerAddress,
                            CustomerID      = cus.CustomerID,
                            CustomerName    = datHangDto.CustomerName,
                            CustomerPhone   = datHangDto.CustomerPhone,
                            StoreID         = stID,
                            ServiceChange   = serviceChange,
                            Sale            = sale,
                            ShippingFee     = shippingFee,
                            TotalPrice      = totalPrice,
                            Status          = 0
                        };
                        if (ModelState.IsValid)
                        {
                            //Thực hiện cập nhận trong model
                            db.Entry(iv).State = System.Data.Entity.EntityState.Added;
                            db.SaveChanges();
                        }

                        foreach (var gh in lstGioHang)
                        {
                            var           foodID = Guid.Parse(gh.FoodID);
                            InvoiceDetail ivDT   = new InvoiceDetail()
                            {
                                InvoiceID  = iv.InvoiceID,
                                FoodID     = foodID,
                                Size       = gh.FoodSize,
                                PriceSize  = (decimal)gh.PriceSize,
                                Type       = gh.FoodType,
                                PriceType  = (Decimal)gh.PriceType,
                                NumberFood = gh.SoLuong,
                            };
                            if (ModelState.IsValid)
                            {
                                //Thực hiện cập nhận trong model
                                db.Entry(ivDT).State = System.Data.Entity.EntityState.Added;
                                db.SaveChanges();
                            }
                        }
                        return(Json(true));
                    }
                }
                catch
                {
                    return(Json(false));
                }
            }
            return(Json(false));
        }