Beispiel #1
0
 public Warehouse[] List()
 {
     using (var dbContext = new AllureContext())
     {
         return(dbContext.Set <Warehouse>().ToArray());
     }
 }
Beispiel #2
0
 public Logistic[] List()
 {
     using (var dbContext = new AllureContext())
     {
         return(dbContext.Set <Logistic>().ToArray());
     }
 }
Beispiel #3
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 #4
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 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));
        }
 public Brand[] List()
 {
     using (var dbContext = new AllureContext())
     {
         return(dbContext.Set <Brand>().ToArray());
     }
 }
Beispiel #8
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 #9
0
 public void Create(Warehouse input)
 {
     using (var dbContext = new AllureContext())
     {
         dbContext.Set <Warehouse>().Add(input);
         dbContext.SaveChanges();
     }
 }
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 Update(Warehouse input)
 {
     using (var dbContext = new AllureContext())
     {
         dbContext.UpdateGraph(input);
         dbContext.SaveChanges();
     }
 }
Beispiel #12
0
        public LocaleOutput Update(Locale locale)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.UpdateGraph(locale, m => m.OwnedCollection(l => l.Localized));
                dbContext.SaveChanges();
            }

            return(new LocaleOutput(locale));
        }
        public Brand Update(Brand brand)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.UpdateGraph(brand);
                dbContext.SaveChanges();
            }

            return(Id(brand.Id));
        }
 private void BuildLanguagesInModel(MainViewModel model)
 {
     using (var dbContext = new AllureContext())
     {
         model.Languages = dbContext
                           .Set <Language>()
                           .Where(lang => lang.Enabled)
                           .ToArray();
     }
 }
        public Brand Create(Brand brand)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.Set <Brand>().Add(brand);
                dbContext.SaveChanges();
            }

            return(Id(brand.Id));
        }
Beispiel #16
0
        public LocaleOutput Create(Locale locale)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.Set <Locale>().Add(locale);
                dbContext.SaveChanges();
            }

            return(new LocaleOutput(locale));
        }
Beispiel #17
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();
                }
            }
        }
        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);
            }
        }
Beispiel #21
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);
            }
        }
Beispiel #24
0
        public CategoryOutput[] List()
        {
            using (var dbContext = new AllureContext())
            {
                var categories = dbContext
                                 .Set <Category>()
                                 .Include(c => c.Localized)
                                 .Include(c => c.Children)
                                 .ToList()
                                 .Select(c => new CategoryOutput(c))
                                 .ToArray();

                return(categories);
            }
        }
        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 #26
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 #27
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();
            }
        }
        public virtual ActionResult List()
        {
            using (var dbContext = new AllureContext())
            {
                var orders = dbContext
                             .Set <Order>()
                             .Include(o => o.Details)
                             .Where(o => o.CustomerId == this.Identity.User.Id)
                             .ToArray()
                             .Select(o => new OrderOutput(o))
                             .ToArray();

                return(View(CreateViewModel(orders)));
            }
        }
Beispiel #29
0
        public void Delete(string id)
        {
            using (var dbContext = new AllureContext())
            {
                var logistic = dbContext.Set <Logistic>().SingleOrDefault(l => l.Code == id);

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

                logistic.Status = DataStatus.Deleted;
                dbContext.SaveChanges();
            }
        }
Beispiel #30
0
        public HomePageImageOutput Create()
        {
            var httpRequest = HttpContext.Current.Request;

            var formData = httpRequest.Form["image"];

            if (formData.IsNullOrEmpty())
            {
                throw new Exception("missing image data");
            }

            if (httpRequest.Files.Count == 0)
            {
                throw new Exception("missing image file");
            }

            var input = JsonConvert.DeserializeObject <HomePageImageInput>(formData);
            var image = new HomePageImage
            {
                Id          = input.Id,
                Width       = input.Width,
                Height      = input.Height,
                NavigateUrl = input.NaviateUrl,
                Localized   = input.Localized.Select(l => new LocalizedHomePageImage
                {
                    HomePageImageId = input.Id,
                    LanguageCode    = l.LanguageCode,
                    Title           = l.Title,
                    Description     = l.Descrption
                }).ToList()
            };

            var file      = httpRequest.Files[0];
            var extension = new System.IO.FileInfo(file.FileName).Extension;
            var imageUrl  = "/UploadImages/" + Guid.NewGuid().ToString() + extension;
            var imageFile = Image.FromStream(file.InputStream);

            imageFile.Save(HttpContext.Current.Server.MapPath("~" + imageUrl));
            image.ImageUrl = imageUrl;

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

            return(Id(image.Id));
        }