public override void Configure(EntityTypeBuilder <CategoryStatusType> builder) { base.Configure(builder); builder.Property(x => x.Name).IsRequired(false).HasColumnName("Name").HasColumnType("nvarchar(50)"); builder.HasData( new CategoryStatusType { Id = 1, Name = "Actived", InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new CategoryStatusType { Id = 2, Name = "Removed", InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }); }
public void Update(CategoryViewModel categoryViewModel) { var oldCategory = _mapper.Map <Category>(GetById(categoryViewModel.Id)); var category = _mapper.Map <Category>(categoryViewModel); category.DateCreated = oldCategory.DateCreated; category.DateModified = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); _categoryRepository.Update(category); _unitOfWork.Commit(); }
public static void Seed(this ModelBuilder modelBuilder) { modelBuilder.Entity <Payment>().HasData( new Payment { Name = "Giao hàng tiết kiếm", } //new Payment { }, ); modelBuilder.Entity <Category>().HasData( new Category { Id = 1, Name = "Category001", InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new Category { Id = 2, Name = "Category002", InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new Category { Id = 3, Name = "Category003", InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new Category { Id = 4, Name = "Category004", InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new Category { Id = 5, Name = "Category005", InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) } ); //modelBuilder.Entity<Product>().HasData( // new Product { Id = 1, Sku = "PD001", Name = "Product001", Description = "DescriptionDescriptionDescriptionDescription", RegularPrice = 100000, DiscountPrice = 100000, Quantity = 10, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, // new Product { Id = 2, Sku = "PD002", Name = "Product002", Description = "DescriptionDescriptionDescriptionDescription", RegularPrice = 10000, DiscountPrice = 10000, Quantity = 10, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, // new Product { Id = 3, Sku = "PD003", Name = "Product003", Description = "DescriptionDescriptionDescriptionDescription", RegularPrice = 1000, DiscountPrice = 1000, Quantity = 10, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, // new Product { Id = 4, Sku = "PD004", Name = "Product004", Description = "DescriptionDescriptionDescriptionDescription", RegularPrice = 100, DiscountPrice = 100, Quantity = 10, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) } //); modelBuilder.Entity <ProductCategory>().HasData( new ProductCategory { ProductId = 1, CategoryId = 1, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new ProductCategory { ProductId = 2, CategoryId = 1, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new ProductCategory { ProductId = 3, CategoryId = 2, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) }, new ProductCategory { ProductId = 4, CategoryId = 4, InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now), UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now) } ); }
public ProductViewModel Add(ProductViewModel productViewModel) { var productTags = new List <ProductTag>(); if (string.IsNullOrEmpty(productViewModel.Tags)) { return(productViewModel); } var tags = productViewModel.Tags.Split(','); foreach (var t in tags) { var tagId = TextHelper.ToUnsignString(t); if (!_tagRepository.GetAll(x => x.Id == tagId).Any()) { var tag = new Tag { Id = tagId, Name = t, Type = CommonConstants.ProductTag }; _tagRepository.Add(tag); } var productTag = new ProductTag { TagId = tagId }; productTags.Add(productTag); } var product = _mapper.Map <Product>(productViewModel); var datimeNow = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); product.DateCreated = datimeNow; product.DateModified = datimeNow; foreach (var productTag in productTags) { product.ProductTags.Add(productTag); } _productRepository.Add(product); _unitOfWork.Commit(); return(productViewModel); }
public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] CategoryViewModel updateCategoryViewModel) { if (!ModelState.IsValid) { //_logger.LogInformation($"End HttpPut PutProduct({id}) - ProductController - BadRequest"); return(BadRequest(ModelState)); } if (id != updateCategoryViewModel.Id) { //_logger.LogInformation($"End HttpPut PutProduct({id}) - ProductController - BadRequest: {id} != {updateProductViewModel.Id}"); return(BadRequest()); } var result = _validator.Validate(updateCategoryViewModel); if (!result.IsValid) { return(BadRequest(result.ToString("~"))); } var category = await _categoryService.GetByIdAsync(id); if (category == null) { //_logger.LogInformation($"End HttpPut PutProduct({id}) - ProductController - NotFound"); return(NotFound()); } try { var updateCategory = _mapper.Map <Category>(updateCategoryViewModel); updateCategory.InsertedAt = category.InsertedAt; updateCategory.UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); await _categoryService.UpdateAsync(updateCategory); //_logger.LogInformation($"End HttpPut PutProduct({id}) - ProductController - Done"); return(Ok()); } catch (Exception e) { //_logger.LogError($"End HttpPut PutProduct({id}) - ProductController - BadRequest: {e.Message}"); return(BadRequest($"Error! {e.Message}")); } }
public override int SaveChanges() { var modified = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified || e.State == EntityState.Added); foreach (EntityEntry item in modified) { IDateTracking changedOrAddedItem = item.Entity as IDateTracking; if (changedOrAddedItem != null) { if (item.State == EntityState.Added) { changedOrAddedItem.DateCreated = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); } changedOrAddedItem.DateModified = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); } } return base.SaveChanges(); }
public void Update(ProductViewModel productViewModel) { var productTags = new List <ProductTag>(); if (!string.IsNullOrEmpty(productViewModel.Tags)) { var tags = productViewModel.Tags.Split(','); foreach (var t in tags) { var tagId = TextHelper.ToUnsignString(t); if (!_tagRepository.GetAll(x => x.Id == tagId).Any()) { var tag = new Tag { Id = tagId, Name = t, Type = CommonConstants.ProductTag }; _tagRepository.Add(tag); } _productTagRepository.RemoveMultiple(_productTagRepository.GetAll(x => x.Id == productViewModel.Id).ToList()); var productTag = new ProductTag { TagId = tagId }; productTags.Add(productTag); } } var oldProduct = _mapper.Map <Product>(GetById(productViewModel.Id)); var product = _mapper.Map <Product>(productViewModel); product.DateCreated = oldProduct.DateCreated; product.DateModified = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); foreach (var item in productTags) { product.ProductTags.Add(item); } _productRepository.Update(product); _unitOfWork.Commit(); }
public async Task CreateAsync(BillViewModel billViewModel) { var bill = _mapper.Map <Bill>(billViewModel); var billDetails = _mapper.Map <List <BillDetail> >(billViewModel.BillDetails); foreach (var item in billDetails) { var product = _productRepository.GetById(item.ProductId); item.Price = product.Price; } bill.BillDetails = billDetails; var dateTimeNow = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); bill.DateCreated = dateTimeNow; bill.DateModified = dateTimeNow; _billRepository.Add(bill); await _unitOfWork.CommitAsync(); }
public async Task UpdateAsync(BlogViewModel blogViewModel) { var blog = _mapper.Map <Blog>(blogViewModel); var dateTimeNow = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); blog.DateCreated = dateTimeNow; blog.DateModified = dateTimeNow; _blogRepository.Update(blog); if (!string.IsNullOrEmpty(blog.Tags)) { string[] tags = blog.Tags.Split(','); foreach (string t in tags) { var tagId = TextHelper.ToUnsignString(t); if (!_tagRepository.GetAll(x => x.Id == tagId).Any()) { var tag = new Tag { Id = tagId, Name = t, Type = CommonConstants.ProductTag }; _tagRepository.Add(tag); } _blogTagRepository.RemoveMultiple(_blogTagRepository.GetAll(x => x.Id == blog.Id).ToList()); var blogTag = new BlogTag { BlogId = blog.Id, TagId = tagId }; _blogTagRepository.Add(blogTag); } } await _unitOfWork.CommitAsync(); }
public async Task <IActionResult> PostPost([FromBody] Post post) { if (!ModelState.IsValid) { Log.Information($"End HttpPost PostPost({post}) - PostController - BadRequest"); return(BadRequest(ModelState)); } try { post.InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); post.UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); await _postService.InsertAsync(post); Log.Information($"End HttpPost PostPost({post}) - PostController - Done"); return(CreatedAtAction("GetPost", new { id = post.Id }, post)); } catch (Exception e) { Log.Information($"End HttpPost PostPost({post}) - BadRequest: {e.Message}"); return(BadRequest(e.Message)); } }
public async Task <IActionResult> PostCategory([FromBody] CategoryViewModel categoryViewModel) { if (!ModelState.IsValid) { //_logger.LogInformation($"End HttpPost PostProduct({productViewModel}) - ProductController - BadRequest"); return(BadRequest(ModelState)); } var resuilt = _validator.Validate(categoryViewModel); if (!resuilt.IsValid) { return(BadRequest(resuilt.ToString("~"))); } try { var category = _mapper.Map <Category>(categoryViewModel); var datetime = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); category.InsertedAt = datetime; category.UpdatedAt = datetime; await _categoryService.InsertAsync(category); //_logger.LogInformation($"End HttpPost PostProduct({productViewModel}) - ProductController - Done"); var newCategoryViewModel = _mapper.Map <CategoryViewModel>(category); return(CreatedAtAction("GetCategory", new { id = newCategoryViewModel.Id }, newCategoryViewModel)); } catch (Exception e) { //_logger.LogError($"End HttpPost PostProduct({productViewModel}) - BadRequest: {e.Message}"); return(BadRequest(e.Message)); } }
public async Task <IActionResult> PostUser([FromBody] User user) { Log.Information($"Start HttpPost PostUser({user}) - UsersController"); if (!ModelState.IsValid) { Log.Information($"End HttpPost PostUser({user}) - UsersController - BadRequest"); return(BadRequest(ModelState)); } try { user.InsertedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); user.UpdatedAt = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); await _userService.InsertAsync(user); Log.Information($"End HttpPost PostUser({user}) - UsersController - Done"); return(CreatedAtAction("GetProduct", new { id = user.Id }, user)); } catch (Exception e) { Log.Information($"End HttpPost PostUser({user}) - BadRequest: {e.Message}"); return(BadRequest(e.Message)); } }
public PagedResult <BillViewModel> GetAllPaging(string keyword, int pageSize, string startDate, string endDate, int pageIndex = 1) { var bills = _billRepository.GetAll(); if (!string.IsNullOrEmpty(startDate)) { var start = Convert.ToInt32(ConvertDatetime.ConvertToTimeSpan(DateTime.ParseExact(startDate, "dd/MM/yyyy", CultureInfo.GetCultureInfo("vi-VN")))); bills = bills.Where(x => Convert.ToInt32(x.DateCreated) >= start); } if (!string.IsNullOrEmpty(endDate)) { var end = Convert.ToInt32(ConvertDatetime.ConvertToTimeSpan(DateTime.ParseExact(endDate, "dd/MM/yyyy", CultureInfo.GetCultureInfo("vi-VN")))); bills = bills.Where(x => Convert.ToInt32(x.DateModified) >= end); } if (!string.IsNullOrEmpty(keyword)) { bills = bills.Where(x => x.CustomerName.Contains(keyword) || x.CustomerMobile.Contains(keyword)); } var totalRow = bills.Count(); bills = bills.OrderByDescending(x => x.DateCreated).Skip((pageIndex - 1) * pageSize).Take(pageSize); var billsViewModel = _mapper.Map <List <BillViewModel> >(bills); var paginationSet = new PagedResult <BillViewModel> { Results = billsViewModel, RowCount = totalRow, PageSize = pageSize, CurrentPage = pageIndex }; return(paginationSet); }
public async Task ImportExcelAsync(string filePath, int categoryId) { using (var package = new ExcelPackage(new FileInfo(filePath))) { ExcelWorksheet workSheet = package.Workbook.Worksheets[1]; for (int i = workSheet.Dimension.Start.Row + 1; i <= workSheet.Dimension.End.Row; i++) { var product = new Product(); product.CategoryId = categoryId; product.Name = workSheet.Cells[i, 1].Value.ToString(); product.Description = workSheet.Cells[i, 2].Value.ToString(); product.Status = Status.Active; try { product.Content = workSheet.Cells[i, 6].Value.ToString(); } catch (Exception) { product.Content = ""; } try { product.SeoKeywords = workSheet.Cells[i, 7].Value.ToString(); } catch (Exception) { product.SeoKeywords = ""; } try { product.SeoDescription = workSheet.Cells[i, 8].Value.ToString(); } catch (Exception) { product.SeoDescription = ""; } decimal.TryParse(workSheet.Cells[i, 3].Value.ToString(), out var originalPrice); product.OriginalPrice = originalPrice; decimal.TryParse(workSheet.Cells[i, 4].Value.ToString(), out var price); product.Price = price; decimal.TryParse(workSheet.Cells[i, 5].Value.ToString(), out var promotionPrice); product.PromotionPrice = promotionPrice; bool.TryParse(workSheet.Cells[i, 9].Value.ToString(), out var hotFlag); product.HotFlag = hotFlag; bool.TryParse(workSheet.Cells[i, 10].Value.ToString(), out var homeFlag); product.HomeFlag = homeFlag; var dateTimeNow = DateTime.Now; product.DateCreated = ConvertDatetime.ConvertToTimeSpan(dateTimeNow); product.DateModified = ConvertDatetime.ConvertToTimeSpan(dateTimeNow); _productRepository.Add(product); await _unitOfWork.CommitAsync(); } } }
public async Task Seed() { var datetime = ConvertDatetime.ConvertToTimeSpan(DateTime.Now); if (!_roleManager.Roles.Any()) { await _roleManager.CreateAsync(new AppRole() { Name = "Admin", NormalizedName = "Admin", Description = "Top manager" }); await _roleManager.CreateAsync(new AppRole() { Name = "Staff", NormalizedName = "Staff", Description = "Staff" }); await _roleManager.CreateAsync(new AppRole() { Name = "Customer", NormalizedName = "Customer", Description = "Customer" }); } if (!_userManager.Users.Any()) { await _userManager.CreateAsync(new AppUser() { UserName = "******", FullName = "Administrator", Email = "*****@*****.**", Balance = 0, PhoneNumberConfirmed = true, TwoFactorEnabled = false, LockoutEnabled = false, AccessFailedCount = 0, Avatar = @"https://sv1.uphinhnhanh.com/images/2019/01/02/logo-new.png", DateCreated = datetime, DateModified = datetime, Status = Status.Active }, "admin"); await _userManager.AddToRoleAsync(await _userManager.FindByNameAsync("admin"), "Admin"); await _userManager.CreateAsync(new AppUser() { UserName = "******", FullName = "Staff", Email = "*****@*****.**", Balance = 0, PhoneNumberConfirmed = true, TwoFactorEnabled = false, LockoutEnabled = false, AccessFailedCount = 0, DateCreated = datetime, DateModified = datetime, Status = Status.Active }, "staff"); await _userManager.AddToRoleAsync(await _userManager.FindByNameAsync("staff"), "Staff"); } if (!_context.Contacts.Any()) { _context.Contacts.Add(new Contact() { Id = CommonConstants.DefaultFooterId, Address = "KTX khu B - ĐHQG TPHCM", Email = "*****@*****.**", Name = "NU Shop", Phone = "0963209769", Status = Status.Active, Website = @"http://nushop.com", Lat = 21.0435009, Lng = 105.7894758 }); } if (_context.Functions.Count() == 0) { _context.Functions.AddRange(new List <Function>() { new Function() { Id = "SYSTEM", Name = "System", ParentId = null, SortOrder = 1, Status = Status.Active, URL = "/", IconCss = "fa-desktop" }, new Function() { Id = "ROLE", Name = "Role", ParentId = "SYSTEM", SortOrder = 1, Status = Status.Active, URL = "/admin/role/index", IconCss = "fa-home" }, new Function() { Id = "FUNCTION", Name = "Function", ParentId = "SYSTEM", SortOrder = 2, Status = Status.Active, URL = "/admin/function/index", IconCss = "fa-home" }, new Function() { Id = "USER", Name = "User", ParentId = "SYSTEM", SortOrder = 3, Status = Status.Active, URL = "/admin/user/index", IconCss = "fa-home" }, new Function() { Id = "ACTIVITY", Name = "Activity", ParentId = "SYSTEM", SortOrder = 4, Status = Status.Active, URL = "/admin/activity/index", IconCss = "fa-home" }, new Function() { Id = "ERROR", Name = "Error", ParentId = "SYSTEM", SortOrder = 5, Status = Status.Active, URL = "/admin/error/index", IconCss = "fa-home" }, new Function() { Id = "SETTING", Name = "Configuration", ParentId = "SYSTEM", SortOrder = 6, Status = Status.Active, URL = "/admin/setting/index", IconCss = "fa-home" }, new Function() { Id = "PRODUCT", Name = "Product Management", ParentId = null, SortOrder = 2, Status = Status.Active, URL = "/", IconCss = "fa-chevron-down" }, new Function() { Id = "CATEGORY", Name = "Category", ParentId = "PRODUCT", SortOrder = 1, Status = Status.Active, URL = "/admin/category/index", IconCss = "fa-chevron-down" }, new Function() { Id = "PRODUCT_LIST", Name = "Product", ParentId = "PRODUCT", SortOrder = 2, Status = Status.Active, URL = "/admin/product/index", IconCss = "fa-chevron-down" }, new Function() { Id = "BILL", Name = "Bill", ParentId = "PRODUCT", SortOrder = 3, Status = Status.Active, URL = "/admin/bill/index", IconCss = "fa-chevron-down" }, new Function() { Id = "CONTENT", Name = "Content", ParentId = null, SortOrder = 3, Status = Status.Active, URL = "/", IconCss = "fa-table" }, new Function() { Id = "BLOG", Name = "Blog", ParentId = "CONTENT", SortOrder = 1, Status = Status.Active, URL = "/admin/blog/index", IconCss = "fa-table" }, new Function() { Id = "PAGE", Name = "Page", ParentId = "CONTENT", SortOrder = 2, Status = Status.Active, URL = "/admin/page/index", IconCss = "fa-table" }, new Function() { Id = "UTILITY", Name = "Utilities", ParentId = null, SortOrder = 4, Status = Status.Active, URL = "/", IconCss = "fa-clone" }, new Function() { Id = "FOOTER", Name = "Footer", ParentId = "UTILITY", SortOrder = 1, Status = Status.Active, URL = "/admin/footer/index", IconCss = "fa-clone" }, new Function() { Id = "FEEDBACK", Name = "Feedback", ParentId = "UTILITY", SortOrder = 2, Status = Status.Active, URL = "/admin/feedback/index", IconCss = "fa-clone" }, new Function() { Id = "ANNOUNCEMENT", Name = "Announcement", ParentId = "UTILITY", SortOrder = 3, Status = Status.Active, URL = "/admin/announcement/index", IconCss = "fa-clone" }, new Function() { Id = "CONTACT", Name = "Contact", ParentId = "UTILITY", SortOrder = 4, Status = Status.Active, URL = "/admin/contact/index", IconCss = "fa-clone" }, new Function() { Id = "SLIDE", Name = "Slide", ParentId = "UTILITY", SortOrder = 5, Status = Status.Active, URL = "/admin/slide/index", IconCss = "fa-clone" }, new Function() { Id = "ADVERTISMENT", Name = "Advertisment", ParentId = "UTILITY", SortOrder = 6, Status = Status.Active, URL = "/admin/advertistment/index", IconCss = "fa-clone" }, new Function() { Id = "REPORT", Name = "Report", ParentId = null, SortOrder = 5, Status = Status.Active, URL = "/", IconCss = "fa-bar-chart-o" }, new Function() { Id = "REVENUES", Name = "Revenue report", ParentId = "REPORT", SortOrder = 1, Status = Status.Active, URL = "/admin/report/revenues", IconCss = "fa-bar-chart-o" }, new Function() { Id = "ACCESS", Name = "Visitor Report", ParentId = "REPORT", SortOrder = 2, Status = Status.Active, URL = "/admin/report/visitor", IconCss = "fa-bar-chart-o" }, new Function() { Id = "READER", Name = "Reader Report", ParentId = "REPORT", SortOrder = 3, Status = Status.Active, URL = "/admin/report/reader", IconCss = "fa-bar-chart-o" }, }); } if (_context.Footers.Count(x => x.Id == CommonConstants.DefaultFooterId) == 0) { string content = "Footer"; _context.Footers.Add(new Footer() { Id = CommonConstants.DefaultFooterId, Content = content }); } if (_context.Colors.Count() == 0) { List <Color> listColor = new List <Color>() { new Color() { Name = "Black", Code = "#000000" }, new Color() { Name = "White", Code = "#FFFFFF" }, new Color() { Name = "Red", Code = "#ff0000" }, new Color() { Name = "Blue", Code = "#1000ff" }, }; _context.Colors.AddRange(listColor); } if (_context.Slides.Count() == 0) { List <Slide> slides = new List <Slide>() { new Slide() { Name = "Slide 1", Image = "/client-side/images/slider/slide-1.jpg", Url = "#", DisplayOrder = 0, GroupAlias = "top", Status = true }, new Slide() { Name = "Slide 2", Image = "/client-side/images/slider/slide-2.jpg", Url = "#", DisplayOrder = 1, GroupAlias = "top", Status = true }, new Slide() { Name = "Slide 3", Image = "/client-side/images/slider/slide-3.jpg", Url = "#", DisplayOrder = 2, GroupAlias = "top", Status = true }, new Slide() { Name = "Slide 1", Image = "/client-side/images/brand1.png", Url = "#", DisplayOrder = 1, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 2", Image = "/client-side/images/brand2.png", Url = "#", DisplayOrder = 2, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 3", Image = "/client-side/images/brand3.png", Url = "#", DisplayOrder = 3, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 4", Image = "/client-side/images/brand4.png", Url = "#", DisplayOrder = 4, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 5", Image = "/client-side/images/brand5.png", Url = "#", DisplayOrder = 5, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 6", Image = "/client-side/images/brand6.png", Url = "#", DisplayOrder = 6, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 7", Image = "/client-side/images/brand7.png", Url = "#", DisplayOrder = 7, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 8", Image = "/client-side/images/brand8.png", Url = "#", DisplayOrder = 8, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 9", Image = "/client-side/images/brand9.png", Url = "#", DisplayOrder = 9, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 10", Image = "/client-side/images/brand10.png", Url = "#", DisplayOrder = 10, GroupAlias = "brand", Status = true }, new Slide() { Name = "Slide 11", Image = "/client-side/images/brand11.png", Url = "#", DisplayOrder = 11, GroupAlias = "brand", Status = true }, }; _context.Slides.AddRange(slides); } 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); } if (_context.Categories.Count() == 0) { List <Category> listProductCategory = new List <Category>() { new Category() { Name = "Men shirt", SeoAlias = "men-shirt", ParentId = null, Status = Status.Active, SortOrder = 1, DateCreated = datetime, DateModified = datetime, Products = new List <Product>() { new Product() { Name = "Product 1", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-1", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 2", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-2", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 3", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-3", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 4", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-4", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 5", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-5", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, } }, new Category() { Name = "Women shirt", SeoAlias = "women-shirt", ParentId = null, Status = Status.Active, SortOrder = 2, DateCreated = datetime, DateModified = datetime, Products = new List <Product>() { new Product() { Name = "Product 6", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-6", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 7", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-7", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 8", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-8", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 9", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-9", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 10", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-10", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, } }, new Category() { Name = "Men shoes", SeoAlias = "men-shoes", ParentId = null, Status = Status.Active, SortOrder = 3, DateCreated = datetime, DateModified = datetime, Products = new List <Product>() { new Product() { Name = "Product 11", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-11", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 12", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-12", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 13", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-13", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 14", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-14", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 15", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-15", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, } }, new Category() { Name = "Woment shoes", SeoAlias = "women-shoes", ParentId = null, Status = Status.Active, SortOrder = 4, DateCreated = datetime, DateModified = datetime, Products = new List <Product>() { new Product() { Name = "Product 16", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-16", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 17", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-17", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 18", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-18", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 19", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-19", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, new Product() { Name = "Product 20", DateCreated = datetime, DateModified = datetime, Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-20", Price = 1000, Status = Status.Active, OriginalPrice = 1000 }, } } }; _context.Categories.AddRange(listProductCategory); } if (!_context.SystemConfigs.Any(x => x.Id == "HomeTitle")) { _context.SystemConfigs.Add(new SystemConfig() { Id = "HomeTitle", Name = "Home's title", Value1 = "Tedu Shop home", Status = Status.Active }); } if (!_context.SystemConfigs.Any(x => x.Id == "HomeMetaKeyword")) { _context.SystemConfigs.Add(new SystemConfig() { Id = "HomeMetaKeyword", Name = "Home Keyword", Value1 = "shopping, sales", Status = Status.Active }); } if (!_context.SystemConfigs.Any(x => x.Id == "HomeMetaDescription")) { _context.SystemConfigs.Add(new SystemConfig() { Id = "HomeMetaDescription", Name = "Home Description", Value1 = "Home tedu", Status = Status.Active }); } await _context.SaveChangesAsync(); }
public MappingProfile() { #region AnnouncementUser CreateMap <AnnouncementUserViewModel, AnnouncementUser>(); CreateMap <AnnouncementUser, AnnouncementUserViewModel>(); #endregion AnnouncementUser #region Announcement CreateMap <AnnouncementViewModel, Announcement>() .ForMember(model => model.DateCreated, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateCreated))) .ForMember(model => model.DateModified, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateModified))); CreateMap <Announcement, AnnouncementViewModel>() .ForMember(viewmodel => viewmodel.DateCreated, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateCreated))) .ForMember(viewmodel => viewmodel.DateModified, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateModified))); #endregion Announcement #region AppRole CreateMap <AppRoleViewModel, AppRole>(); CreateMap <AppRole, AppRoleViewModel>(); #endregion AppRole #region AppUser CreateMap <AppUserViewModel, AppUser>() .ForMember(model => model.DateCreated, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateCreated))) .ForMember(model => model.DateModified, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateModified))); CreateMap <AppUser, AppUserViewModel>() .ForMember(viewmodel => viewmodel.DateCreated, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateCreated))) .ForMember(viewmodel => viewmodel.DateModified, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateModified))); #endregion AppUser #region BillDetail CreateMap <BillDetailViewModel, BillDetail>(); CreateMap <BillDetail, BillDetailViewModel>(); #endregion BillDetail #region Bill CreateMap <BillViewModel, Bill>() .ForMember(model => model.DateCreated, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateCreated))) .ForMember(model => model.DateModified, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateModified))); CreateMap <Bill, BillViewModel>() .ForMember(viewmodel => viewmodel.DateCreated, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateCreated))) .ForMember(viewmodel => viewmodel.DateModified, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateModified))); #endregion Bill #region BlogTag CreateMap <BlogTagViewModel, BlogTag>(); CreateMap <BlogTag, BlogTagViewModel>(); #endregion BlogTag #region Blog CreateMap <BlogViewModel, Blog>() .ForMember(model => model.DateCreated, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateCreated))) .ForMember(model => model.DateModified, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateModified))); CreateMap <Blog, BlogViewModel>() .ForMember(viewmodel => viewmodel.DateCreated, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateCreated))) .ForMember(viewmodel => viewmodel.DateModified, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateModified))); #endregion Blog #region Category CreateMap <CategoryViewModel, Category>() .ForMember(model => model.DateCreated, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateCreated))) .ForMember(model => model.DateModified, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateModified))); CreateMap <Category, CategoryViewModel>() .ForMember(viewmodel => viewmodel.DateCreated, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateCreated))) .ForMember(viewmodel => viewmodel.DateModified, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateModified))); #endregion Category #region Color CreateMap <ColorViewModel, Color>(); CreateMap <Color, ColorViewModel>(); #endregion Color #region Contact CreateMap <ContactViewModel, Contact>(); CreateMap <Contact, ContactViewModel>(); #endregion Contact #region Feedback CreateMap <FeedbackViewModel, Feedback>() .ForMember(model => model.DateCreated, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateCreated))) .ForMember(model => model.DateModified, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateModified))); CreateMap <Feedback, FeedbackViewModel>() .ForMember(viewmodel => viewmodel.DateCreated, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateCreated))) .ForMember(viewmodel => viewmodel.DateModified, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateModified))); #endregion Feedback #region Footer CreateMap <FooterViewModel, Footer>(); CreateMap <Footer, FooterViewModel>(); #endregion Footer #region Function CreateMap <FunctionViewModel, Function>(); CreateMap <Function, FunctionViewModel>(); #endregion Function #region Permission CreateMap <PermissionViewModel, Permission>(); CreateMap <Permission, PermissionViewModel>(); #endregion Permission #region ProductImage CreateMap <ProductImageViewModel, ProductImage>(); CreateMap <ProductImage, ProductImageViewModel>(); #endregion ProductImage #region ProductQuantity CreateMap <ProductQuantityViewModel, ProductQuantity>(); CreateMap <ProductQuantity, ProductQuantityViewModel>(); #endregion ProductQuantity #region Product CreateMap <ProductViewModel, Product>() .ForMember(model => model.DateCreated, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateCreated))) .ForMember(model => model.DateModified, opt => opt.MapFrom(viewmodel => ConvertDatetime.ConvertToTimeSpan(viewmodel.DateModified))); CreateMap <Product, ProductViewModel>() .ForMember(viewmodel => viewmodel.DateCreated, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateCreated))) .ForMember(viewmodel => viewmodel.DateModified, opt => opt.MapFrom(model => ConvertDatetime.UnixTimestampToDateTime(model.DateModified))); #endregion Product #region SinglePage CreateMap <SinglePageViewModel, SinglePage>(); CreateMap <Feedback, SinglePageViewModel>(); #endregion SinglePage #region Size CreateMap <SizeViewModel, Size>(); CreateMap <Size, SizeViewModel>(); #endregion Size #region Slide CreateMap <SlideViewModel, Slide>(); CreateMap <Slide, SlideViewModel>(); #endregion Slide #region SystemConfig CreateMap <SystemConfigViewModel, SystemConfig>(); CreateMap <SystemConfig, SystemConfigViewModel>(); #endregion SystemConfig #region Tag CreateMap <TagViewModel, Tag>(); CreateMap <Tag, TagViewModel>(); #endregion Tag #region WholePrice CreateMap <WholePriceViewModel, WholePrice>(); CreateMap <WholePrice, WholePriceViewModel>(); #endregion WholePrice }