Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
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()));
        }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
 public void Create(Logistic input)
 {
     using (var dbContext = new AllureContext())
     {
         dbContext.Set <Logistic>().Add(input);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public void Create(Warehouse input)
 {
     using (var dbContext = new AllureContext())
     {
         dbContext.Set <Warehouse>().Add(input);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void Update(Warehouse input)
 {
     using (var dbContext = new AllureContext())
     {
         dbContext.UpdateGraph(input);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 7
0
        public Brand Create(Brand brand)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.Set <Brand>().Add(brand);
                dbContext.SaveChanges();
            }

            return(Id(brand.Id));
        }
Exemplo n.º 8
0
        public LocaleOutput Create(Locale locale)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.Set <Locale>().Add(locale);
                dbContext.SaveChanges();
            }

            return(new LocaleOutput(locale));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
        public Brand Update(Brand brand)
        {
            using (var dbContext = new AllureContext())
            {
                dbContext.UpdateGraph(brand);
                dbContext.SaveChanges();
            }

            return(Id(brand.Id));
        }
Exemplo n.º 11
0
        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();
                }
            }
        }
Exemplo n.º 12
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();
            }
        }
Exemplo n.º 13
0
        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();
            }
        }
Exemplo n.º 14
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();
            }
        }
Exemplo n.º 15
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));
        }
Exemplo n.º 16
0
        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();
            }
        }
Exemplo n.º 17
0
        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();
            }
        }
Exemplo n.º 18
0
        public void Delete(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var locale = dbContext
                             .Set <Locale>()
                             .Include(l => l.Localized)
                             .SingleOrDefault(l => l.Id == id);

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

                locale.Status = DataStatus.Deleted;
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 19
0
        public SubCategoryOutput CreateSub()
        {
            var httpRequest = HttpContext.Current.Request;

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

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

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

            var image = httpRequest.Files[0];
            var url   = "/UploadImages/" + Guid.NewGuid().ToString() + new System.IO.FileInfo(image.FileName).Extension;

            image.SaveAs(HttpContext.Current.Server.MapPath("~" + url));

            var input       = JsonConvert.DeserializeObject <SubCategoryInput>(formData);
            var subCategory = new SubCategory
            {
                ParentId  = input.ParentId,
                ImageUrl  = url,
                Localized = input.Localized
                            .Select(x => new LocalizedSubCategory
                {
                    LanguageCode = x.LanguageCode,
                    Name         = x.Name,
                    Description  = x.Description
                })
                            .ToList()
            };

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

            return(SubId(subCategory.Id));
        }
Exemplo n.º 20
0
        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"));
            }
        }
Exemplo n.º 21
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();
            }
        }
Exemplo n.º 22
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();
            }
        }
Exemplo n.º 23
0
        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();
                }
            }
        }
Exemplo n.º 24
0
        public void Delete(int id)
        {
            using (var dbContext = new AllureContext())
            {
                var product = dbContext
                              .Set <Product>()
                              .Include(p => p.Localized)
                              .Include(p => p.Images)
                              .Include(p => p.Storage)
                              .SingleOrDefault(p => p.Id == id);

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

                product.Status = DataStatus.Deleted;
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 25
0
        public CategoryOutput Create(CategoryInput input)
        {
            var category = new Category
            {
                Localized = input.Localized.Select(i => new LocalizedCategory
                {
                    LanguageCode = i.LanguageCode,
                    Name         = i.Name,
                    Description  = i.Description
                }).ToList()
            };

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

            return(Id(category.Id));
        }
Exemplo n.º 26
0
        public StorageOperationOutput Update(UpdateStorageOperationInput input)
        {
            using (var dbContext = new AllureContext())
            {
                var operation = dbContext
                                .Set <StorageOperation>()
                                .Include(s => s.Details)
                                .SingleOrDefault(s => s.Id == input.Id);

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

                operation.LogisticFee = input.LogisticFee;
                operation.UpdateDate  = DateTime.Today;
                dbContext.SaveChanges();

                return(new StorageOperationOutput(operation));
            }
        }
Exemplo n.º 27
0
        public virtual ActionResult Activate(string username, string token)
        {
            var decrypted = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(token));
            var valid     = decrypted.StartsWith(prefix);

            if (valid)
            {
                var email = decrypted.Substring(prefix.Length, decrypted.Length - prefix.Length);
                using (var context = new AllureContext())
                {
                    var user = context.Set <User>().Single(u => u.Email == email);
                    user.Status = UserStatus.Normal;
                    context.SaveChanges();
                }

                return(View(MVC.User.Views.ActivateSuccess, CreateViewModel()));
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
Exemplo n.º 28
0
        public void Add(string id)
        {
            using (var dbContext = new AllureContext())
            {
                var supported = CultureInfo.GetCultures(CultureTypes.SpecificCultures);

                if (supported.Any(c => c.Name.Equals(id)))
                {
                    var lang = dbContext.Set <Language>().SingleOrDefault(l => l.Code == id);

                    if (lang == null)
                    {
                        lang = new Language {
                            Code = id
                        };
                    }

                    lang.Enabled = true;

                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 29
0
        public CategoryOutput Update(CategoryInput input)
        {
            var category = new Category
            {
                Id        = input.Id,
                Localized = input.Localized
                            .Select(c => new LocalizedCategory
                {
                    CategoryId   = input.Id,
                    LanguageCode = c.LanguageCode,
                    Name         = c.Name,
                    Description  = c.Description
                }).ToList()
            };

            using (var dbContext = new AllureContext())
            {
                dbContext.UpdateGraph(category, m => m.OwnedCollection(c => c.Localized));
                dbContext.SaveChanges();
            }

            return(Id(category.Id));
        }
Exemplo n.º 30
0
        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"));
            }
        }