public ActionResult Details(int? id)
 {
     var marketingActual = new MarketingActual();
     if (id.HasValue)
     {
         var ma = Services.ContentService.GetById(id.Value);
         marketingActual.ID = ma.Id;
         marketingActual.Name = ma.Name;
         marketingActual.Thumbnail = JsonConvert.DeserializeObject<ImageCropDataSet>(ma.GetValue<string>("nThumbnail"));
         marketingActual.Description = ma.GetValue<string>("nDescription");
         marketingActual.Content = ma.GetValue<HtmlString>("nContent");
         marketingActual.IsPublished = ma.Published;
         marketingActual.Date = ma.GetValue<DateTime>("nDate").ToString("dd.MM.yyyy");
     }
     else
     {
         marketingActual.Date = DateTime.Now.ToString("dd.MM.yyyy");
     }
     return PartialView(marketingActual);
 }
        public ActionResult MarketingActualSubmit(MarketingActual marketingActual)
        {
            if (!ModelState.IsValid || marketingActual == null)
                return CurrentUmbracoPage();

            var company = Company();
            var contentService = Services.ContentService;

            IContent ma = null;
            if (!marketingActual.ID.HasValue)
            {
                var maParent = umbracoHelper.TypedContentAtRoot().First().FirstChild(x => x.ContentType.Alias.Equals("dtNewsList"));
                ma = contentService.CreateContent(marketingActual.Name, maParent.Id, "dtNews", Members.GetCurrentMemberId());
            }
            else
                ma = contentService.GetById(marketingActual.ID.Value);

            ma.Name = marketingActual.Name;
            ma.SetValue("nCompanyNodeId", company.Id);
            ma.SetValue("nDescription", marketingActual.Description);
            ma.SetValue("nContent", marketingActual.Content);
            if (marketingActual.NewThumbnail != null && marketingActual.NewThumbnail.InputStream != null)
            {
                var filename = JobsplusHelpers.RemoveDiacritics(Path.GetFileName(marketingActual.NewThumbnail.FileName));

                var path = "/media/" + ma.Id.ToString() + "/";
                var fullPath = Server.MapPath("~" + path);
                var dir = new DirectoryInfo(fullPath);
                if (!dir.Exists)
                    dir.Create();
                try
                {

                    marketingActual.NewThumbnail.SaveAs(fullPath + filename);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "Při nahrávání náhledového obrázku došlo k chybě:");
                    TempData.Add("ValidationErrorInfo", JobsplusHelpers.GetMsgFromException(ex));
                    return CurrentUmbracoPage();
                }
                var filepath = path + filename;
                Image img = null;
                try
                {
                    img = Image.FromFile(fullPath + filename);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "Nahrávaný soubor náhledového obrázku nemá správný formát:");
                    System.IO.File.Delete(fullPath + filename);
                    TempData.Add("ValidationErrorInfo", JobsplusHelpers.GetMsgFromException(ex));
                    return CurrentUmbracoPage();
                }

                var newThumbnail = new ImageCropDataSet();
                newThumbnail.FocalPoint.Left = new decimal(0.5);
                newThumbnail.FocalPoint.Top = new decimal(0.5);
                newThumbnail.Src = filepath;
                ma.SetValue("nThumbnail", newThumbnail);
            }
            contentService.Save(ma);

            if (marketingActual.IsPublished)
                contentService.Publish(ma);
            else
                contentService.UnPublish(ma);

            return Redirect("/firma/marketingove-aktuality/");
        }