예제 #1
0
        static void Main()
        {
            try
            {
                var dbContext = new DataContext();
                //dbContext.Database.ExecuteSqlCommand("delete from category");
                dbContext.Database.ExecuteSqlCommand("delete from product");
                dbContext.Database.ExecuteSqlCommand("delete from [order]");

                var order = new Order {Id = 1, Buyer = "Foobar"};
                order.Products = new List<Product>();
                var product = new Product {Id = 2, Name = "Foobar"};
                order.Products.Add(product);

                dbContext.Orders.Add(order);
                //dbContext.Products.Add();
                //dbContext.Categories.Add(new Category() {Id = 3, Name = "Foobar"});

                dbContext.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #2
0
        public void SaveAndPublish() {
            var languageId = Language.CurrentLanguageId;

            using (var context = new DataContext())
            {
                var siteEntity = context.Sites.SingleOrDefault(x => x.SiteId == SiteId);

                if (siteEntity == null) {
                    siteEntity = new SiteEntity {
                        SiteId = SiteId
                    };

                    context.Add(siteEntity);
                    context.SaveChanges();
                }

                siteEntity.Author = HttpContext.Current.User.Identity.Name;
                siteEntity.ChildSortDirection = ChildSortDirection;
                siteEntity.ChildSortOrder = ChildSortOrder;
                siteEntity.Name = Name;
                siteEntity.UpdateDate = DateTime.Now.ToUniversalTime();

                context.SaveChanges();

                // ---------------

                var propertiesForSite = context.SiteProperties.Where(x => x.SiteId == SiteId && x.LanguageId == languageId).ToList();

                foreach (var propertyItem in Property) {
                    var propertyEntity = propertiesForSite.Find(c => c.PropertyId == propertyItem.PropertyId);

                    if (propertyEntity == null) {
                        propertyEntity = new SitePropertyEntity {
                            LanguageId = languageId,
                            SiteId = SiteId,
                            PropertyId = propertyItem.PropertyId
                        };
                        context.Add(propertyEntity);
                        propertiesForSite.Add(propertyEntity);
                    }

                    propertyEntity.SiteData = GetSerializedPropertyValue(propertyItem);
                }

                context.SaveChanges();
            }

            SiteFactory.UpdateSite(this);
            CacheManager.RemoveRelated(SiteId);


            SiteFactory.RaiseSitePublished(SiteId, languageId);
        }
예제 #3
0
        private static Dictionary<string, TagContext> GetTagContexts() {
            var contexts = new Dictionary<string, TagContext>();

            // TODO: Replace with single query if possible
            using (var context = new DataContext()) {
                var tagContexts = Mapper.Map<List<TagContextEntity>, List<TagContext>>(context.TagContexts.ToList());
                var tags = Mapper.Map<List<TagEntity>, List<Tag>>(context.Tags.ToList());
                var pageTags = Mapper.Map<List<PageTagEntity>, List<PageTag>>(context.PageTags.ToList());

                foreach (var tagContext in tagContexts) {
                    AddTagsToContext(tagContext, tags, pageTags);
                    contexts.Add(tagContext.ContextName.ToLowerInvariant(), tagContext);
                }
            }

            return contexts;
        }
예제 #4
0
 private static void AddPageLinksToDatabase(IEnumerable<RedirectEntity> redirects) {
     using (var context = new DataContext()) {
         foreach (var redirect in redirects) {
             if (context.Redirects.Any(r => r.UrlHash == redirect.UrlHash)) {
                 continue;
             }
             
             context.Add(redirect);
         }
         try {
             context.SaveChanges();
         }
         catch (Exception exception) {
             Logger.Write(exception, Logger.Severity.Major);
         }
     }
 }
        public void Seed(DataContext context)
        {
            new List<Role>()
                {
                    new Role()
                        {
                            RoleId = 1,
                            RoleName = "Super Admin"
                        }
                }.ForEach(a => context.Roles.AddOrUpdate(a));

            new List<User>()
                {
                    new User()
                        {
                            UserId = 1,
                            Email = "*****@*****.**",
                            Username = "******",
                            FirstName = "Rod",
                            LastName = "Johnson",
                            LastLoginDate = DateTime.Now,
                            Password = "******",
                            IsApproved = true,
                            Gender = Gender.Male,
                            Address = "Admin address",
                            PhoneNumber = "555-555-5555"
                        }
                }.ForEach(u => context.Users.AddOrUpdate(u));

            /*
            var existsInRole = context.UserClaims.Any(ur => ur.UserId == 1 && ur.UserId == 1);

            if (!existsInRole)
            {
                new List<UserClaim>()
                {
                    new UserClaim()
                        {
                            Type = "1",
                            UserId = 1
                        }
                }.ForEach(ur => context.UserClaims.Add(ur));
            }
            */
        }
        public void Seed(DataContext context)
        {
            var user = new User()
                {
                    Id = 1,
                    Email = "*****@*****.**",
                    Username = "******",
                    FirstName = "Rod",
                    LastName = "Johnson",
                    LastLogin = DateTime.UtcNow,
                    Gender = Gender.Male,
                    Address = "Admin address",
                    PhoneNumber = "555-555-5555",
                    IsLoginAllowed = true,
                    IsAccountClosed = false,
                    IsAccountVerified = true,
                    Created = DateTime.UtcNow,
                    Tenant = "default",
                    // password is "admin"
                    HashedPassword = "******",
                    PasswordChanged = DateTime.UtcNow,
                    FailedLoginCount = 0,
                    Updated = DateTime.UtcNow
                };

            user.Claims.Add(new UserClaim()
                {
                    Type = ClaimTypes.Role,
                    Value = "Admin"
                });

            user.Claims.Add(new UserClaim()
            {
                Type = ClaimTypes.Role,
                Value = "Super Admin"
            });

            context.Users.AddOrUpdate(user);
            context.SaveChanges();
        }
 public void InitialSetup()
 {
     _context = new DataContext("MySqlContext");
 }
예제 #8
0
        private void UnpublishCurrentVersion(DataContext context) {
            var pageInstance = context.PageInstances.SingleOrDefault(x => x.PageId == PageId && x.LanguageId == LanguageId && x.Status == PageInstanceStatus.Published);

            if (pageInstance == null) {
                return;
            }

            pageInstance.Status = PageInstanceStatus.Archived;
            context.SaveChanges();

            Data.PropertyData.RemovePropertiesFromCache(PageId, LanguageId, pageInstance.CurrentVersion);

            if (pageInstance.PageUrl != UrlSegment) {
                var currentPage = PageFactory.GetPage(PageId, LanguageId);
                RedirectManager.StorePageLinks(currentPage);
            }

        }
예제 #9
0
        public void Publish(bool keepAsWorkingCopy = false) {
            using (var context = new DataContext()) {
                var pageInstance = context.PageInstances.Single(x => x.PageInstanceId == PageInstanceId);

                if (keepAsWorkingCopy && pageInstance.CurrentVersion != 1) {
                    throw new Exception("Only the very first working copy need to be stored without being published using the keepAsWorkingCopy flag");
                }

                if (!keepAsWorkingCopy) {
                    if (pageInstance.StartPublish == null) {
                        pageInstance.StartPublish = DateTime.Now.ToUniversalTime();
                    }

                    UnpublishCurrentVersion(context);
                    
                    pageInstance.Status = PageInstanceStatus.Published;
                    context.SaveChanges();
                }

                PageFactory.UpdatePageIndex(pageInstance, ParentId, RootId, TreeLevel, PageTypeId, SortIndex);
                CacheManager.RemoveRelated(ParentId);
                CacheManager.RemoveRelated(PageId);

                if (!keepAsWorkingCopy) {
                    PageFactory.RaisePagePublished(PageId, LanguageId, CurrentVersion);
                }
            }
        }
예제 #10
0
        public void Save() {
            using (var context = new DataContext()) {
                var pageEntity = context.Pages.SingleOrDefault(x => x.PageId == PageId);

                if (pageEntity == null) {
                    pageEntity = new PageEntity {
                        PageId = PageId,
                        PageTypeId = PageTypeId,
                        ParentId = ParentId,
                        RootId = RootId,
                        SortOrder = SortIndex,
                        TreeLevel = TreeLevel
                    };

                    context.Add(pageEntity);
                    context.SaveChanges();
                }

                // ---------------

                var pageInstance = context.PageInstances.SingleOrDefault(x => x.PageInstanceId == PageInstanceId);

                if (pageInstance == null) {
                    CurrentVersion = context.PageInstances.Where(x => x.PageId == PageId && x.LanguageId == LanguageId).Max(x => x.CurrentVersion) + 1;

                    pageInstance = new PageInstanceEntity {
                        PageId = PageId,
                        LanguageId = LanguageId,
                        CreatedDate = DateTime.Now.ToUniversalTime(),
                        CurrentVersion = CurrentVersion,
                        Status = PageInstanceStatus.WorkingCopy
                    };

                    context.Add(pageInstance);
                }

                pageInstance.Author = HttpContext.Current.User.Identity.Name;
                pageInstance.ChildSortDirection = ChildSortDirection;
                pageInstance.ChildSortOrder = ChildSortOrder;
                pageInstance.PageName = PageName;
                pageInstance.StartPublish = StartPublish;
                pageInstance.StopPublish = StopPublish;
                pageInstance.UpdateDate = DateTime.Now.ToUniversalTime();
                pageInstance.VisibleInMenu = VisibleInMenu;
                pageInstance.VisibleInSitemap = VisibleInSiteMap;
                
                EnsurePageUrl();

                pageInstance.PageUrl = UrlSegment;

                context.SaveChanges();

                PageInstanceId = pageInstance.PageInstanceId;

                // ---------------

                var pagePropertiesForPage = context.PageProperties.Where(x => x.PageId == PageId && x.LanguageId == LanguageId && x.Version == CurrentVersion).ToList();

                foreach (var propertyItem in Property) {
                    var propertyEntity = pagePropertiesForPage.Find(c => c.PropertyId == propertyItem.PropertyId);

                    if (propertyEntity == null) {
                        propertyEntity = new PagePropertyEntity {
                            LanguageId = LanguageId,
                            PageId = PageId,
                            PropertyId = propertyItem.PropertyId,
                            Version = CurrentVersion
                        };
                        context.Add(propertyEntity);
                        pagePropertiesForPage.Add(propertyEntity);
                    }

                    propertyEntity.PageData = GetSerializedPropertyValue(propertyItem);
                }

                context.SaveChanges();
            }

            // Allow property types to execute code when a property of that type is saved
            foreach (var propertyItem in Property) {
                if (propertyItem == null) {
                    continue;
                }

                var propertyData = propertyItem.PropertyData as IPageSavedHandler;
                if (propertyData != null) {
                    propertyData.PageSaved(this);
                }
            }

            if (CurrentVersion == 1) {
                Publish(true);
            }

            PageFactory.RaisePageSaved(PageId, LanguageId, CurrentVersion);
        }
        public string PaymentLink(string totalCost, string paymentSubjetc, string order_id)
        {
            string paymentMode = ConfigurationManager.AppSettings["PaymentMode"], site, merchantId, merchantKey, returnUrl, cancelUrl, PF_NotifyURL;

            if (paymentMode == "test")
            {
                site        = "https://sandbox.payfast.co.za/eng/process?";
                merchantId  = "10017134";
                merchantKey = "dzhxjfvzun252";
            }
            else if (paymentMode == "live")
            {
                site        = "https://www.payfast.co.za/eng/process?";
                merchantId  = ConfigurationManager.AppSettings["PF_MerchantID"];
                merchantKey = ConfigurationManager.AppSettings["PF_MerchantKey"];
            }
            else
            {
                throw new InvalidOperationException("Payment method unknown.");
            }
            var stringBuilder = new StringBuilder();

            //PF_NotifyURL = Url.Action("Payment_Successfull", "Shopping",
            //    new System.Web.Routing.RouteValueDictionary(new { id = order_id }),
            //    "http", Request.Url.Host);
            //returnUrl = Url.Action("Order_Details", "Orders",
            //    new System.Web.Routing.RouteValueDictionary(new { id = order_id }),
            //    "http", Request.Url.Host);
            //cancelUrl = Url.Action("Index", "Shopping",
            //    new System.Web.Routing.RouteValueDictionary(new { id = order_id }),
            //    "http", Request.Url.Host);

            PF_NotifyURL = ConfigurationManager.AppSettings["NotifyURL"];
            returnUrl    = Url.Action();
            cancelUrl    = ConfigurationManager.AppSettings["CancelURL"];
            /* mechant details */
            stringBuilder.Append("&merchant_id=" + HttpUtility.HtmlEncode(merchantId));
            stringBuilder.Append("&merchant_key=" + HttpUtility.HtmlEncode(merchantKey));
            stringBuilder.Append("&return_url=" + HttpUtility.HtmlEncode(returnUrl));
            stringBuilder.Append("&cancel_url=" + HttpUtility.HtmlEncode(cancelUrl));
            stringBuilder.Append("&notify_url=" + HttpUtility.HtmlEncode(PF_NotifyURL));
            /* buyer details */
            Data.DataContext db = new Data.DataContext();
            var customer        = _orderRepository.Find(x => x.OrderNo.ToString() == order_id).FirstOrDefault();


            //db.Orders.FirstOrDefault(x => x.OrderNo.ToString() == order_id).customer;
            if (customer != null)
            {
                stringBuilder.Append("&name_first=" + HttpUtility.HtmlEncode(customer.FirstName));
                stringBuilder.Append("&name_last=" + HttpUtility.HtmlEncode(customer.LastName));
                stringBuilder.Append("&email_address=" + HttpUtility.HtmlEncode(customer.Email));
                //stringBuilder.Append("&cell_number=" + HttpUtility.HtmlEncode(customer.phone));
            }
            /* Transaction details */
            var order = _orderRepository.GetById(Convert.ToInt32(order_id));

            if (order != null)
            {
                decimal pricetot = (decimal)cart_Service.GetCartTotal(cart_Service.GetCartID());
                stringBuilder.Append("&m_payment_id=" + HttpUtility.HtmlEncode(order.OrderNo));
                stringBuilder.Append("&amount=" + HttpUtility.HtmlEncode((double)order.TotalPrice));
                stringBuilder.Append("&item_name=" + HttpUtility.HtmlEncode(paymentSubjetc));
                stringBuilder.Append("&item_description=" + HttpUtility.HtmlEncode(paymentSubjetc));

                stringBuilder.Append("&email_confirmation=" + HttpUtility.HtmlEncode("1"));
                stringBuilder.Append("&confirmation_address=" + HttpUtility.HtmlEncode(ConfigurationManager.AppSettings["PF_ConfirmationAddress"]));
            }

            return(site + stringBuilder);
        }
 public void InitialSetup()
 {
     _context = new DataContext("SqlServerContext");
 }
예제 #13
0
 public MemberStore(DataContext context) : base(context)
 {
 }