Ejemplo n.º 1
0
        // PUT api/ApiTickets/5
        public IHttpActionResult PutTicket()
        {
            var ticketJson = Request.Content.ReadAsStringAsync().Result;
            var ticket     = (new System.Web.Script.Serialization.JavaScriptSerializer()).Deserialize <Ticket>(ticketJson.ToString());


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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TicketExists(ticket.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        // PUT api/ApiTickets/5
        public IHttpActionResult PutTicket(int id, Ticket ticket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ticket.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult CreateUser()
        {
            var userJson = Request.Content.ReadAsStringAsync().Result;

            var user = (new System.Web.Script.Serialization.JavaScriptSerializer()).Deserialize <User>(userJson.ToString());

            db.Users.Add(user);
            db.SaveChanges();
            return(Ok());
        }
Ejemplo n.º 4
0
        public void CreateSizes(int ProductId, string SizeId)
        {
            int sz = 0;

            Int32.TryParse(SizeId, out sz);

            var product = _context.Products.Include(p => p.AvalableSizes).FirstOrDefault(p => p.Id == ProductId);
            //product.AvalableSizes = _context.ProductSizes.Where(pr => pr.ProductId == ProductId).ToList();
            var size = _context.Sizes.FirstOrDefault(s => s.Id == sz);

            //if (_context.ProductSizes.Any(pr => pr.ProductId == ProductId & pr.SizeId == sz))
            //{
            //    // do nothing
            //    NotFound();
            //    return;
            //}

            var ps = new ProductSizes
            {
                ProductId = product.Id,
                SizeId    = size.Id
            };

            product.AvalableSizes.Add(ps);
            _context.SaveChanges();
        }
Ejemplo n.º 5
0
 private void CreateSize(MyShopDbContext context)
 {
     if (context.Sizes.Count() == 0)
     {
         List <Size> listSize = new List <Size>()
         {
             new Size()
             {
                 Name = "XXL"
             },
             new Size()
             {
                 Name = "XL"
             },
             new Size()
             {
                 Name = "L"
             },
             new Size()
             {
                 Name = "M"
             },
             new Size()
             {
                 Name = "S"
             },
             new Size()
             {
                 Name = "XS"
             }
         };
         context.Sizes.AddRange(listSize);
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 private void CreatePage(MyShopDbContext context)
 {
     if (context.Pages.Count() == 0)
     {
         try
         {
             var page = new Page()
             {
                 Name    = "Giới thiệu",
                 Alias   = "gioi-thieu",
                 Content = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium ",
                 Status  = true
             };
             context.Pages.Add(page);
             context.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             foreach (var eve in ex.EntityValidationErrors)
             {
                 Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error.");
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"");
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
 private void CreateContactDetail(MyShopDbContext context)
 {
     if (context.ContactDetails.Count() == 0)
     {
         try
         {
             var contactDetail = new ContactDetail()
             {
                 Name    = "Shop thời trang TEDU",
                 Address = "Ngõ 123 trần cung",
                 Email   = "*****@*****.**",
                 Lat     = 21.0633645,
                 Lng     = 105.8053274,
                 Phone   = "0967680605",
                 Website = "http://thoitrangsinhvien.com.vn",
                 Other   = "",
                 Status  = true
             };
             context.ContactDetails.Add(contactDetail);
             context.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             foreach (var eve in ex.EntityValidationErrors)
             {
                 Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error.");
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"");
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 private void CreateColor(MyShopDbContext context)
 {
     if (context.Colors.Count() == 0)
     {
         List <Color> listColor = new List <Color>()
         {
             new Color()
             {
                 Name = "Đen", Code = "#000000"
             },
             new Color()
             {
                 Name = "Trắng", Code = "#FFFFFF"
             },
             new Color()
             {
                 Name = "Đỏ", Code = "#ff0000"
             },
             new Color()
             {
                 Name = "Xanh", Code = "#1000ff"
             },
         };
         context.Colors.AddRange(listColor);
         context.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 private void CreateProductCategorySample(MyShopDbContext context)
 {
     if (context.ProductCategories.Count() == 0)
     {
         List <ProductCategory> listProductCategory = new List <ProductCategory>()
         {
             new ProductCategory()
             {
                 Name = "Áo nam", Alias = "ao-nam", Status = true
             },
             new ProductCategory()
             {
                 Name = "Áo nữ", Alias = "ao-nu", Status = true
             },
             new ProductCategory()
             {
                 Name = "Giày nam", Alias = "giay-nam", Status = true
             },
             new ProductCategory()
             {
                 Name = "Giày nữ", Alias = "giay-nu", Status = true
             }
         };
         context.ProductCategories.AddRange(listProductCategory);
         context.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 private void CreateFooter(MyShopDbContext context)
 {
     if (context.Footers.Count(x => x.ID == CommonConstants.DefaultFooterId) == 0)
     {
         string content = "Footer";
         context.Footers.Add(new Footer()
         {
             ID      = CommonConstants.DefaultFooterId,
             Content = content
         });
         context.SaveChanges();
     }
 }
Ejemplo n.º 11
0
        // GET api/Token
        public IHttpActionResult GetToken(string clientid, string clientsecret, string code)
        {
            var tokenrow = db.Tokens.Where(
                t => t.Code == code).Join(db.Applications, t => t.ApplicationId, a => a.Id, (token, application) =>
                                          (application.ClientIdentifier == clientid && application.ClientSecret == clientsecret) ? token : null).SingleOrDefault();

            if (tokenrow == null)
            {
                return(BadRequest());
            }
            var tokenstring = BitConverter.ToString(
                MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(tokenrow.Code + tokenrow.UserId + DateTime.Now.ToString()))).Replace("-", "");

            tokenrow.TokenString = tokenstring;
            tokenrow.Code        = "puhad";
            tokenrow.TokenExpirationDateTimeUtc = DateTime.UtcNow.AddHours(1);
            tokenrow.TokenRepair = BitConverter.ToString(
                MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(tokenrow.Code + DateTime.Now.AddHours(1) + tokenrow.UserId + DateTime.Now.ToString()))).Replace("-", "");
            var response = this.Request.CreateResponse(HttpStatusCode.OK);

            db.SaveChanges();
            return(Json(new { Data = new { token = tokenstring, expiration = tokenrow.TokenExpirationDateTimeUtc } }));
        }
Ejemplo n.º 12
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,Ip,Operation,Good,Sex,Address,CreatedOn")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Ip = GetRemoteIP();
                //user.Sex = true;
                user.Address = GetAddress(user.Ip);
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Ejemplo n.º 13
0
 public ActionResult AuthorizeApplicationSubmit(string ClientId)
 {
     if (Session["userid"] != null)
     {
         var ap   = db.Applications.SingleOrDefault(a => a.ClientIdentifier == ClientId);
         var code = BitConverter.ToString(
             MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(Session["userid"].ToString() + DateTime.Now.ToString()))).Replace("-", string.Empty);
         db.Tokens.AddOrUpdate(token => token.ApplicationId,
                               new Token()
         {
             ApplicationId = ap.Id,
             UserId        = (int)Session["userid"],
             Code          = code
         });
         db.SaveChanges();
         TempData["infMessage"] = "application authorized";
         return(Redirect(ap.RedirectUrl + "?code=" + code));
     }
     TempData["infMessage"] = "you need authorize";
     return(RedirectToAction("Index", "Home"));
 }
Ejemplo n.º 14
0
 private void CreateSlide(MyShopDbContext context)
 {
     if (context.Slides.Count() == 0)
     {
         List <Slide> listSlide = new List <Slide>()
         {
             new Slide()
             {
                 Name         = "Slide 1",
                 DisplayOrder = 1,
                 Status       = true,
                 Url          = "#",
                 Image        = "/Assets/client/images/bag.jpg",
                 Content      = @"	<h2>FLAT 50% 0FF</h2>
                         <label>FOR ALL PURCHASE <b>VALUE</b></label>
                         <p>Lorem ipsum dolor sit amet, consectetur
                     adipisicing elit, sed do eiusmod tempor incididunt ut labore et </ p >
                 <span class=""on-get"">GET NOW</span>"
             },
             new Slide()
             {
                 Name         = "Slide 2",
                 DisplayOrder = 2,
                 Status       = true,
                 Url          = "#",
                 Image        = "/Assets/client/images/bag1.jpg",
                 Content      = @"<h2>FLAT 50% 0FF</h2>
                         <label>FOR ALL PURCHASE <b>VALUE</b></label>
                         <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et </ p >
                         <span class=""on-get"">GET NOW</span>"
             },
         };
         context.Slides.AddRange(listSlide);
         context.SaveChanges();
     }
 }
Ejemplo n.º 15
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
Ejemplo n.º 16
0
        private void CreateFunction(MyShopDbContext context)
        {
            if (context.Functions.Count() == 0)
            {
                context.Functions.AddRange(new List <Function>()
                {
                    new Function()
                    {
                        ID = "SYSTEM", Name = "Hệ thống", ParentId = null, DisplayOrder = 1, Status = true, URL = "/", IconCss = "fa-desktop"
                    },
                    new Function()
                    {
                        ID = "ROLE", Name = "Nhóm", ParentId = "SYSTEM", DisplayOrder = 1, Status = true, URL = "/main/role/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        ID = "FUNCTION", Name = "Chức năng", ParentId = "SYSTEM", DisplayOrder = 2, Status = true, URL = "/main/function/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        ID = "USER", Name = "Người dùng", ParentId = "SYSTEM", DisplayOrder = 3, Status = true, URL = "/main/user/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        ID = "ACTIVITY", Name = "Nhật ký", ParentId = "SYSTEM", DisplayOrder = 4, Status = true, URL = "/main/activity/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        ID = "ERROR", Name = "Lỗi", ParentId = "SYSTEM", DisplayOrder = 5, Status = true, URL = "/main/error/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        ID = "SETTING", Name = "Cấu hình", ParentId = "SYSTEM", DisplayOrder = 6, Status = true, URL = "/main/setting/index", IconCss = "fa-home"
                    },

                    new Function()
                    {
                        ID = "PRODUCT", Name = "Sản phẩm", ParentId = null, DisplayOrder = 2, Status = true, URL = "/", IconCss = "fa-chevron-down"
                    },
                    new Function()
                    {
                        ID = "PRODUCT_CATEGORY", Name = "Danh mục", ParentId = "PRODUCT", DisplayOrder = 1, Status = true, URL = "/main/product-category/index", IconCss = "fa-chevron-down"
                    },
                    new Function()
                    {
                        ID = "PRODUCT_LIST", Name = "Sản phẩm", ParentId = "PRODUCT", DisplayOrder = 2, Status = true, URL = "/main/product/index", IconCss = "fa-chevron-down"
                    },
                    new Function()
                    {
                        ID = "ORDER", Name = "Hóa đơn", ParentId = "PRODUCT", DisplayOrder = 3, Status = true, URL = "/main/order/index", IconCss = "fa-chevron-down"
                    },

                    new Function()
                    {
                        ID = "CONTENT", Name = "Nội dung", ParentId = null, DisplayOrder = 3, Status = true, URL = "/", IconCss = "fa-table"
                    },
                    new Function()
                    {
                        ID = "POST_CATEGORY", Name = "Danh mục", ParentId = "CONTENT", DisplayOrder = 1, Status = true, URL = "/main/post-category/index", IconCss = "fa-table"
                    },
                    new Function()
                    {
                        ID = "POST", Name = "Bài viết", ParentId = "CONTENT", DisplayOrder = 2, Status = true, URL = "/main/post/index", IconCss = "fa-table"
                    },

                    new Function()
                    {
                        ID = "UTILITY", Name = "Tiện ích", ParentId = null, DisplayOrder = 4, Status = true, URL = "/", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        ID = "FOOTER", Name = "Footer", ParentId = "UTILITY", DisplayOrder = 1, Status = true, URL = "/main/footer/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        ID = "FEEDBACK", Name = "Phản hồi", ParentId = "UTILITY", DisplayOrder = 2, Status = true, URL = "/main/feedback/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        ID = "ANNOUNCEMENT", Name = "Thông báo", ParentId = "UTILITY", DisplayOrder = 3, Status = true, URL = "/main/announcement/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        ID = "CONTACT", Name = "Lien hệ", ParentId = "UTILITY", DisplayOrder = 4, Status = true, URL = "/main/contact/index", IconCss = "fa-clone"
                    },

                    new Function()
                    {
                        ID = "REPORT", Name = "Báo cáo", ParentId = null, DisplayOrder = 5, Status = true, URL = "/", IconCss = "fa-bar-chart-o"
                    },
                    new Function()
                    {
                        ID = "REVENUES", Name = "Báo cáo doanh thu", ParentId = "REPORT", DisplayOrder = 1, Status = true, URL = "/main/report/revenues", IconCss = "fa-bar-chart-o"
                    },
                    new Function()
                    {
                        ID = "ACCESS", Name = "Báo cáo truy cập", ParentId = "REPORT", DisplayOrder = 2, Status = true, URL = "/main/report/visitor", IconCss = "fa-bar-chart-o"
                    },
                    new Function()
                    {
                        ID = "READER", Name = "Báo cáo độc giả", ParentId = "REPORT", DisplayOrder = 3, Status = true, URL = "/main/report/reader", IconCss = "fa-bar-chart-o"
                    },
                });
                context.SaveChanges();
            }
        }
Ejemplo n.º 17
0
 public IEnumerable <Tienda> Get()
 {
     CreateLog("GET");
     context.SaveChanges();
     return(context.Tiendas.ToList());
 }