private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
 {
     foreach (var item in e.PublishedEntities)
     {
         if (item.ContentType.Alias == "page")
         {
             try
             {
                 bywhoEntities db      = new bywhoEntities();
                 int           pguid   = item.GetValue <int>("pageId");
                 var           topic   = db.Topic.FirstOrDefault(x => x.Id == pguid);
                 var           baseURL = "/cms";
                 if (topic != null)
                 {
                     topic.Title          = item.GetValue <string>("title");
                     topic.SystemName     = item.GetValue <string>("systemName");
                     topic.BodyTekst      = TemplateUtilities.ResolveMediaFromTextString(item.GetValue <string>("bodyText"));
                     topic.IsPage         = item.GetValue <bool>("isPage");
                     topic.SeoTitle       = item.GetValue <string>("seoTitle");
                     topic.SeoDescription = item.GetValue <string>("seoDescription");
                     topic.SeoKeywords    = item.GetValue <string>("seoKeywords");
                     topic.NoFollow       = item.GetValue <bool>("noFollow");
                     db.SaveChanges();
                 }
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
 private void ContentService_Unpublished(IContentService sender, PublishEventArgs <Umbraco.Core.Models.IContent> e)
 {
     foreach (var item in e.PublishedEntities)
     {
         if (item.ContentType.Alias == "materiale")
         {
             try
             {
                 try
                 {
                     using (bywhoEntities db = new bywhoEntities())
                     {
                         Materials mat = null;
                         var       id  = item.GetValue <string>("materialeId");
                         mat = db.Materials.FirstOrDefault(x => x.Id.ToString() == id);
                         if (mat != null)
                         {
                             mat.Published = false;
                             db.SaveChanges();
                         }
                     }
                 }
                 catch
                 {
                 }
             }
             catch
             {
             }
         }
     }
 }
 private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
 {
     foreach (var item in e.PublishedEntities)
     {
         if (item.ContentType.Alias == "materiale")
         {
             try
             {
                 using (bywhoEntities db = new bywhoEntities())
                 {
                     Materials mat = null;
                     var       id  = item.GetValue <string>("materialeId");
                     mat = db.Materials.FirstOrDefault(x => x.Id.ToString() == id);
                     if (mat == null)
                     {
                         mat = new Materials();
                         PopulateModel(item, mat, true);
                         db.Materials.Add(mat);
                         db.SaveChanges();
                         item.SetValue("materialeId", mat.Id.ToString());
                         sender.SaveAndPublish(item, raiseEvents: false);
                     }
                     else
                     {
                         PopulateModel(item, mat, true);
                         db.SaveChanges();
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }
        private async Task <long> GetOrderId(bywhoEntities db)
        {
            using (var cmd = db.Database.Connection.CreateCommand())
            {
                cmd.CommandText = "spOrderId";
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                await db.Database.Connection.OpenAsync();

                long orderId = (long)(await cmd.ExecuteScalarAsync());
                db.Database.Connection.Close();
                return(orderId);
            }
        }
Example #5
0
 public async Task <object> GetAll()
 {
     try
     {
         using (bywhoEntities db = new bywhoEntities())
         {
             return(Newtonsoft.Json.JsonConvert.SerializeObject(await db.Materials.ToListAsync()));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
 {
     foreach (var item in e.PublishedEntities)
     {
         if (item.ContentType.Alias == "product")
         {
             try
             {
                 bywhoEntities db      = new bywhoEntities();
                 Guid          pguid   = Guid.Parse(item.GetValue <string>("productId"));
                 var           style   = db.Styles.FirstOrDefault(x => x.Id == pguid);
                 var           baseURL = "/cms";
                 if (style != null)
                 {
                     style.Name             = item.GetValue <string>("productName");
                     style.Description      = item.GetValue <string>("description");
                     style.Price            = item.GetValue <decimal>("price");
                     style.OldPrice         = item.GetValue <decimal>("oldPrice");
                     style.Picture          = baseURL + item.GetValue <string>("picture");
                     style.Poster           = baseURL + item.GetValue <string>("poster");
                     style.AmountOfPictures = (int)item.GetValue <decimal>("amountOfPictures");
                     style.Published        = item.GetValue <bool>("published");
                     style.HasText          = item.GetValue <bool>("hasTextInStyle");
                     style.SeoTitle         = item.GetValue <string>("seoTitle");
                     style.SeoDescription   = item.GetValue <string>("seoDescription");
                     style.SeoKeywords      = item.GetValue <string>("seoKeywords");
                     style.NoFollow         = item.GetValue <bool>("noFollow");
                     db.SaveChanges();
                 }
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
        private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
        {
            foreach (var item in e.PublishedEntities)
            {
                if (item.ContentType.Alias == "resource")
                {
                    try
                    {
                        bywhoEntities db         = new bywhoEntities();
                        string        systemName = item.Name;
                        var           resource   = db.Resources.FirstOrDefault(x => x.Name == systemName);

                        if (resource != null)
                        {
                            resource.Value = item.GetValue <string>("text");
                            db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
        public async Task <string> CreateOrder(long tnxid, string orderid, string custId, int amount, int currency, string date, string time, string hash)
        {
            try
            {
                using (bywhoEntities db = new bywhoEntities())
                {
                    long orderId = await GetOrderId(db);

                    Guid customerId = Guid.Parse(custId);
                    var  customer   = await db.Customers.FirstOrDefaultAsync(x => x.Id == customerId);

                    //TOTO FETCH  CART
                    var order = _contentService.Create("ORDER-" + orderId, 1221, "order");
                    order.SetValue("orderId", orderId.ToString());
                    order.SetValue("navn", customer.Name);
                    order.SetValue("addresse", customer.Address);
                    order.SetValue("postnr", customer.Zipcode);
                    order.SetValue("by", customer.City);
                    order.SetValue("telefonnummer", customer.Phone);
                    order.SetValue("email", customer.Email);
                    order.SetValue("cartid", orderid);
                    order.SetValue("transaktionsid", tnxid.ToString());
                    _contentService.SaveAndPublish(order);
                    var orderLines = db.CartLines.Where(x => x.CustomerId == customerId).ToList();
                    int i          = 1;
                    foreach (var item in orderLines)
                    {
                        var orderline = _contentService.Create("OrderLine-" + i, order.Id, "orderline");
                        orderline.SetValue("product", item.Styles.Name);
                        orderline.SetValue("quantity", item.Quantity);
                        orderline.SetValue("price", item.Price);
                        orderline.SetValue("text", item.Text);
                        orderline.SetValue("comments", item.Comments);
                        orderline.SetValue("size", db.Sizes.Find(item.SizeId).Name);
                        _contentService.SaveAndPublish(orderline);
                        var images = db.Picture.Where(x => x.CartLineId == item.Id);
                        int j      = 1;

                        foreach (var pic in images)
                        {
                            var imageContent = _contentService.Create("image-" + j, orderline.Id, "uploadedImage");
                            var fileName     = Guid.NewGuid().ToString() + "." + pic.Path.Split('.')[1];
                            var file         = System.IO.File.Open(pic.Path, System.IO.FileMode.Open);
                            //var media = Services.MediaService.CreateMedia(fileName, 1240, Constants.Conventions.MediaTypes.File);
                            //media.SetValue(Services.ContentTypeBaseServices, Constants.Conventions.Media.File, fileName,file);
                            //Services.MediaService.Save(media);
                            //imageContent.SetValue("image", file);
                            int    lastIndex = pic.Path.LastIndexOf("\\") + 1;
                            string filename  = pic.Path.Substring(lastIndex, pic.Path.Length - lastIndex);
                            imageContent.SetValue(Services.ContentTypeBaseServices, "image", filename, file);

                            _contentService.SaveAndPublish(imageContent);
                            j++;
                        }
                        i++;
                    }
                    var body = SendConfirmationMail(customer, orderLines, order);
                    order.SetValue("mail", body);
                    _contentService.SaveAndPublish(order);

                    return(body);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }