Beispiel #1
0
        public virtual ActionResult Index(int id)
        {
            var model = new CategoryIndex();

            using (var dbContext = new AllureContext())
            {
                var current = dbContext.Set <SubCategory>().SingleOrDefault(c => c.Id == id);

                if (current == null)
                {
                    throw new HttpException(404, string.Format("category {0} doesn't exist", id.ToString()));
                }

                model.Current = new SubCategoryOutput(current, this.LanguageCode);

                model.SubCategories = dbContext.Set <SubCategory>()
                                      .Include(c => c.Localized)
                                      .Where(c => c.ParentId == current.ParentId)
                                      .ToArray()
                                      .Select(c => new SubCategoryOutput(c, this.LanguageCode))
                                      .ToArray();

                model.Products = dbContext.Set <Product>()
                                 .Include(p => p.Locale)
                                 .Include(p => p.Localized)
                                 .Where(p => p.SubCategoryId == current.Id)
                                 .ToArray()
                                 .Select(p => new ProductOutput(p, this.LanguageCode))
                                 .ToArray();
            }

            return(View(CreateViewModel(model)));
        }
Beispiel #2
0
        void context_BeginRequest(object sender, EventArgs e)
        {
            var dbContext   = new AllureContext();
            var application = (HttpApplication)sender;

            string[] supported = dbContext.Set <Language>().Where(lang => lang.Enabled).Select(lang => lang.Code).ToArray();

            string querySpecified = application.Request.QueryString[SpecifiedLanguageQueryString];

            if (!querySpecified.IsNullOrEmpty() && supported.Contains(querySpecified))
            {
                SetCulture(application.Response, querySpecified);
                return;
            }

            string headerSpecified = application.Request.Headers[SpecifiedLanguageHeader];

            if (!headerSpecified.IsNullOrEmpty() && supported.Contains(headerSpecified))
            {
                SetCulture(application.Response, headerSpecified);
                return;
            }

            var cookieSpecified = application.Request.Cookies[SpecifiedLanguageCookieName];

            if (cookieSpecified != null && supported.Contains(cookieSpecified.Value))
            {
                SetCulture(application.Response, cookieSpecified.Value);
                return;
            }

            string browserSpecified = application.Request.UserLanguages.FirstOrDefault(l => supported.Contains(l));

            SetCulture(application.Response, browserSpecified ?? dbContext.Set <Language>().Single(lang => lang.IsDefault).Code);
        }
        public OrderOutput Update(OrderInput input)
        {
            using (var dbContext = new AllureContext())
            {
                var order = dbContext.Set <Order>().SingleOrDefault(o => o.Id == input.Id);

                if (order == null)
                {
                    throw new HttpException(404, string.Format("order {0} doesn't exist", input.Id.ToString()));
                }

                order.Status              = input.Status;
                order.WillCheck           = input.WillCheck;
                order.CheckAddress        = input.CheckAddress;
                order.CheckTime           = input.CheckTime;
                order.CheckContact        = input.CheckContact;
                order.LogisticCode        = input.LogisticCode;
                order.LogisticOrderNumber = input.LogisticOrderNumber;
                order.Deposit             = input.Deposit;
                order.DepositReceipt      = input.DepositReceipt;
                order.Remaining           = input.Remaining;
                order.RemainingReceipt    = input.RemainingReceipt;
                order.UpdateTime          = DateTime.Now;
                if (order.Deposit.HasValue)
                {
                    order.RealCharge = order.OriginalRealCharge - order.Deposit.Value;
                }

                dbContext.SaveChanges();

                return(Id(order.Id));
            }
        }
        public void Delete(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var order = dbContext.Set <Order>().SingleOrDefault(o => o.Id == id);

                if (order == null)
                {
                    throw new HttpException(404, string.Format("order {0} doesn't exist", id.ToString()));
                }

                dbContext.Set <OrderDetail>().RemoveRange(order.Details);
                dbContext.Entry(order).State = EntityState.Deleted;
                dbContext.SaveChanges();
            }
        }
Beispiel #5
0
        public virtual ActionResult Register(UserRegister reg)
        {
            var user = new User
            {
                Email     = reg.Email,
                FirstName = reg.FirstName,
                LastName  = reg.LastName,
                Address   = reg.Address,
                Company   = reg.Company,
                Gender    = reg.Gender,
                Mobile    = reg.Mobile,
                Password  = reg.PlainTextPassword,
                PostCode  = reg.PostCode,
                Telephone = reg.Telephone,
                Status    = UserStatus.Unactivated,
                Roles     = new[] { new UserRole {
                                        Role = Role.Customer
                                    } },
                Deliveries = new[] { new Delivery {
                                         Address = reg.Address, Phone = reg.Mobile, PostCode = reg.PostCode, Receiver = reg.FirstName + " " + reg.LastName
                                     } }
            };

            using (var context = new AllureContext())
            {
                context.Set <User>().Add(user);
                context.SaveChanges();
            }

            ViewBag.ActivateUrl = "/user/activate?token=" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(prefix + user.Email));

            return(View(MVC.User.Views.RegisterSuccess, CreateViewModel()));
        }
Beispiel #6
0
 public Warehouse[] List()
 {
     using (var dbContext = new AllureContext())
     {
         return(dbContext.Set <Warehouse>().ToArray());
     }
 }
 public Brand[] List()
 {
     using (var dbContext = new AllureContext())
     {
         return(dbContext.Set <Brand>().ToArray());
     }
 }
Beispiel #8
0
 public Logistic[] List()
 {
     using (var dbContext = new AllureContext())
     {
         return(dbContext.Set <Logistic>().ToArray());
     }
 }
        public UserOutput Create(CreateUserInput input)
        {
            var user = new User
            {
                Email     = input.Email,
                Gender    = input.Gender,
                FirstName = input.FirstName,
                LastName  = input.LastName,
                Telephone = input.Telephone,
                Mobile    = input.Mobile,
                Company   = input.Company,
                Roles     = input.Roles.Select(r => new UserRole {
                    Role = r
                }).ToList(),
                Deliveries = input.Deliveries.Select(d => new Delivery {
                    Address = d.Address, PostCode = d.PostCode, Receiver = d.Receiver, Phone = d.Phone
                }).ToList(),
                Status = UserStatus.Unactivated
            };

            using (var dbContext = new AllureContext())
            {
                dbContext.Set <User>().Add(user);
                dbContext.SaveChanges();
            }

            return(Id(user.Id));
        }
Beispiel #10
0
 public void Create(Logistic input)
 {
     using (var dbContext = new AllureContext())
     {
         dbContext.Set <Logistic>().Add(input);
         dbContext.SaveChanges();
     }
 }
Beispiel #11
0
 public void Create(Warehouse input)
 {
     using (var dbContext = new AllureContext())
     {
         dbContext.Set <Warehouse>().Add(input);
         dbContext.SaveChanges();
     }
 }
        public void Delete(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var user = dbContext.Set <User>().SingleOrDefault(u => u.Id == id);

                if (user == null)
                {
                    throw new HttpException(404, string.Format("user {0} doesn't exist", id.ToString()));
                }

                dbContext.Set <UserRole>().RemoveRange(user.Roles);
                dbContext.Set <Delivery>().RemoveRange(user.Deliveries);
                dbContext.Entry(user).State = EntityState.Deleted;
                dbContext.SaveChanges();
            }
        }
Beispiel #13
0
        public LocaleOutput Create(Locale locale)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.Set <Locale>().Add(locale);
                dbContext.SaveChanges();
            }

            return(new LocaleOutput(locale));
        }
        public Brand Create(Brand brand)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.Set <Brand>().Add(brand);
                dbContext.SaveChanges();
            }

            return(Id(brand.Id));
        }
Beispiel #15
0
        public void Delete(string id)
        {
            using (var dbContext = new AllureContext())
            {
                var image = dbContext
                            .Set <HomePageImage>()
                            .Include(i => i.Localized)
                            .SingleOrDefault(i => i.Id == id);

                if (image == null)
                {
                    throw new HttpException(404, string.Format("image {0} doesn't exist", id.ToString()));
                }

                dbContext.Set <LocalizedHomePageImage>().RemoveRange(image.Localized);
                dbContext.Entry(image).State = EntityState.Deleted;
                dbContext.SaveChanges();
            }
        }
Beispiel #16
0
        public void DeleteSub(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var subCategory = dbContext
                                  .Set <SubCategory>()
                                  .Include(c => c.Localized)
                                  .SingleOrDefault(c => c.Id == id);

                if (subCategory == null)
                {
                    throw new Exception(string.Format("subcategory {0} doesn't exist", id.ToString()));
                }

                dbContext.Set <LocalizedSubCategory>().RemoveRange(subCategory.Localized);
                dbContext.Entry(subCategory).State = EntityState.Deleted;
                dbContext.SaveChanges();
            }
        }
 private void BuildLanguagesInModel(MainViewModel model)
 {
     using (var dbContext = new AllureContext())
     {
         model.Languages = dbContext
                           .Set <Language>()
                           .Where(lang => lang.Enabled)
                           .ToArray();
     }
 }
        public virtual ActionResult Save(OrderInput input)
        {
            using (var context = new AllureContext())
            {
                var order = context.Set <Order>()
                            .Include(o => o.Details)
                            .AsNoTracking()
                            .SingleOrDefault(o => o.Id == input.Id);

                if (order == null)
                {
                    throw new Exception(string.Format("order {0} doesn't exist", input.Id.ToString()));
                }

                var ids      = input.Details.Select(d => d.ProductId).ToArray();
                var products = context.Set <Product>().Where(p => ids.Contains(p.Id)).ToDictionary(p => p.Id);

                var details = input.Details.Where(d => d.Count > 0).Select(d => new OrderDetail
                {
                    ProductId = d.ProductId,
                    Count     = d.Count,
                    Discount  = 0m
                });

                order.WillCheck          = input.WillCheck;
                order.CheckTime          = input.WillCheck ? input.CheckTime : null;
                order.CheckContact       = input.CheckContact;
                order.CheckAddress       = input.CheckAddress;
                order.ReceiverName       = input.ReceiverName;
                order.ReceiverAddress    = input.ReceiverAddress;
                order.ReceiverPostCode   = input.ReceiverPostCode;
                order.ReceiverContact    = input.ReceiverContact;
                order.Details            = details.ToList();
                order.OriginalRealCharge = order.Details.Sum(d => d.RealCharge);
                order.RealCharge         = order.OriginalRealCharge;
                order.UpdateTime         = DateTime.Now;

                context.UpdateGraph(order, o => o.OwnedCollection(oo => oo.Details));
                context.SaveChanges();

                return(Json("ok"));
            }
        }
        public void SetDefault(string id)
        {
            using (var dbContext = new AllureContext())
            {
                var defaultLang = dbContext.Set <Language>().Single(l => l.IsDefault);

                if (!defaultLang.Code.Equals(id))
                {
                    var lang = dbContext.Set <Language>().SingleOrDefault(l => l.Code == id);
                    if (lang == null)
                    {
                        throw new Exception(string.Format("the language {0} isn't active yet.", id));
                    }

                    lang.IsDefault        = true;
                    defaultLang.IsDefault = false;
                    dbContext.SaveChanges();
                }
            }
        }
Beispiel #20
0
 public LocaleOutput[] List()
 {
     using (var dbContext = new AllureContext())
     {
         return(dbContext
                .Set <Locale>()
                .Include(l => l.Localized)
                .ToArray()
                .Select(l => new LocaleOutput(l))
                .ToArray());
     }
 }
 private void BuildCategoryInModel(MainViewModel model)
 {
     using (var dbContext = new AllureContext())
     {
         model.Categories = dbContext
                            .Set <Category>()
                            .Include(c => c.Localized)
                            .Include(c => c.Children)
                            .ToList()
                            .Select(c => new CategoryOutput(c, this.LanguageCode))
                            .ToArray();
     }
 }
        public void Delete(string id)
        {
            using (var dbContext = new AllureContext())
            {
                var lang = dbContext.Set <Language>().SingleOrDefault(l => l.Code == id);

                if (lang != null)
                {
                    lang.Enabled = false;
                    dbContext.SaveChanges();
                }
            }
        }
Beispiel #23
0
        public virtual ActionResult EmailExists(string email)
        {
            var valid = false;

            if (!string.IsNullOrEmpty(email))
            {
                using (var context = new AllureContext())
                {
                    valid = !context.Set <User>().Any(u => u.Email == email);
                }
            }

            return(Content(valid.ToString().ToLowerInvariant()));
        }
        public OrderOutput Id(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var order = dbContext.Set <Order>().SingleOrDefault(o => o.Id == id);

                if (order == null)
                {
                    throw new HttpException(404, string.Format("order {0} doesn't exist", id.ToString()));
                }

                return(new OrderOutput(order));
            }
        }
        public LanguageOutput[] Current()
        {
            using (var dbContext = new AllureContext())
            {
                var languages = dbContext
                                .Set <Language>()
                                .Where(l => l.Enabled)
                                .ToList()
                                .Select(lang => new LanguageOutput(lang))
                                .ToArray();

                return(languages);
            }
        }
        public Brand Id(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var brand = dbContext.Set <Brand>().SingleOrDefault(b => b.Id == id);

                if (brand == null)
                {
                    throw new HttpException(404, string.Format("brand {0} doesn't exist", id.ToString()));
                }

                return(brand);
            }
        }
        public virtual ActionResult Submit(OrderInput input)
        {
            using (var context = new AllureContext())
            {
                var ids      = input.Details.Select(d => d.ProductId).ToArray();
                var products = context.Set <Product>().Where(p => ids.Contains(p.Id)).ToDictionary(p => p.Id);

                var details = input.Details.Where(d => d.Count > 0).Select(d => new OrderDetail
                {
                    ProductId = d.ProductId,
                    Count     = d.Count,
                    Discount  = 0m
                });

                var order = new Order
                {
                    WillCheck        = input.WillCheck,
                    CheckTime        = input.WillCheck ? input.CheckTime : null,
                    CheckContact     = input.CheckContact,
                    CheckAddress     = input.CheckAddress,
                    ReceiverName     = input.ReceiverName,
                    ReceiverAddress  = input.ReceiverAddress,
                    ReceiverPostCode = input.ReceiverPostCode,
                    ReceiverContact  = input.ReceiverContact,
                    Details          = details.ToArray(),
                    Status           = OrderStatus.New,
                    CustomerId       = this.Identity.User.Id,
                    CreateTime       = DateTime.Now,
                    UpdateTime       = DateTime.Now
                };

                context.Set <Order>().Add(order);
                context.SaveChanges();

                return(Json("ok"));
            }
        }
        public void Delete(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var brand = dbContext.Set <Brand>().SingleOrDefault(b => b.Id == id);

                if (brand == null)
                {
                    throw new Exception(string.Format("brand {0} doesn't exist", id.ToString()));
                }

                brand.Status = DataStatus.Deleted;
                dbContext.SaveChanges();
            }
        }
Beispiel #29
0
        public virtual ActionResult Products(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var products = dbContext.Set <Product>()
                               .Include(p => p.Locale)
                               .Include(p => p.Localized)
                               .Where(p => p.SubCategoryId == id)
                               .ToArray()
                               .Select(p => new ProductOutput(p, this.LanguageCode))
                               .ToArray();

                return(Json(products, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #30
0
        public void Delete(string id)
        {
            using (var dbContext = new AllureContext())
            {
                var warehouse = dbContext.Set <Warehouse>().SingleOrDefault(l => l.Code == id);

                if (warehouse == null)
                {
                    throw new HttpException(404, string.Format("Warehouse {0} doesn't exist", id.ToString()));
                }

                warehouse.Status = DataStatus.Deleted;
                dbContext.SaveChanges();
            }
        }