コード例 #1
0
        public ActionResult Create(ChallengeModel model, HttpPostedFileBase contentImage, HttpPostedFileBase contentCoverImage, List <string> videoyoutube, string existingTags, string newTags)
        {
            ChallengeRepository objchallenge = new ChallengeRepository(this.SessionCustom);
            ContentManagement   objcontent   = new ContentManagement(this.SessionCustom, HttpContext);

            try
            {
                DateTime?currentEndDate = null;
                if (model.IContent.ContentId.HasValue)
                {
                    objchallenge.Entity.ContentId = model.IContent.ContentId;
                    objchallenge.LoadByKey();
                    currentEndDate      = objchallenge.Entity.EndDate;
                    objchallenge.Entity = new Domain.Entities.Challenge();
                }

                objcontent.ContentImage      = contentImage;
                objcontent.ContentCoverImage = contentCoverImage;
                objcontent.CollVideos        = videoyoutube;
                this.SessionCustom.Begin();

                model.IContent.LanguageId = CurrentLanguage.LanguageId;
                objcontent.ContentInsert(model.IContent);
                objchallenge.Entity = model.Challenge;
                objchallenge.Entity.ExistingTags = !string.Empty.Equals(existingTags) ? existingTags : null;
                objchallenge.Entity.NewTags      = !string.Empty.Equals(newTags) ? newTags : null;

                if (objchallenge.Entity.ContentId != null)
                {
                    objchallenge.Update();

                    bool reactivated = false;
                    if (currentEndDate < DateTime.Now.Date && model.Challenge.EndDate >= DateTime.Now.Date)
                    {
                        reactivated = true;
                    }

                    if (reactivated)
                    {
                        ContentRepository content = new ContentRepository(SessionCustom);
                        content.Entity.ContentId = model.Challenge.ContentId;
                        content.LoadByKey();
                        Business.Utilities.Notification.StartReActivateProcess(content.Entity.Frienlyname, content.Entity.ContentId.Value, this.HttpContext, this.CurrentLanguage);
                    }

                    this.InsertAudit("Update", this.Module.Name + " -> " + model.IContent.Name);
                }
                else
                {
                    if (!string.IsNullOrEmpty(Request.Form["TempFiles"]))
                    {
                        string[] files = Request.Form["TempFiles"].Split(',');

                        if (files.Length > 0)
                        {
                            if (!Directory.Exists(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\")))
                            {
                                Directory.CreateDirectory(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\"));
                            }
                        }

                        foreach (var item in files)
                        {
                            string filep = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item));
                            if (System.IO.File.Exists(filep))
                            {
                                string filedestin = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item));
                                System.IO.File.Move(filep, Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\" + Path.GetFileName(item)));
                            }
                        }
                    }

                    objchallenge.Entity.ContentId = objcontent.ObjContent.ContentId;
                    objchallenge.Entity.Followers = 0;
                    objchallenge.Insert();

                    ContentRepository content = new ContentRepository(SessionCustom);
                    content.Entity.ContentId = model.Challenge.ContentId;
                    content.LoadByKey();

                    ////EmailNotificationRepository emailNotification = new EmailNotificationRepository(SessionCustom);
                    ////List<int> users = emailNotification.SendNewProcessNotification();
                    ////foreach (int userId in users)
                    ////{
                    ////    Business.Utilities.Notification.NewNotification(userId, Domain.Entities.Basic.EmailNotificationType.NEW_PROCESS, null, null, string.Concat("/", content.Entity.Frienlyname), content.Entity.ContentId, content.Entity.ContentId.Value, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage);
                    ////}

                    Business.Utilities.Notification.StartNewProcess(content.Entity.Frienlyname, content.Entity.ContentId.Value, this.HttpContext, this.CurrentLanguage);

                    this.InsertAudit("Insert", this.Module.Name + " -> " + model.IContent.Name);
                }

                this.SessionCustom.Commit();
            }
            catch (Exception ex)
            {
                SessionCustom.RollBack();
                Utils.InsertLog(
                    this.SessionCustom,
                    "Error" + this.Module.Name,
                    ex.Message + " " + ex.StackTrace);
            }

            if (Request.Form["GetOut"] == "0")
            {
                return(this.RedirectToAction("Index", "Content", new { mod = Module.ModulId }));
            }
            else
            {
                return(this.RedirectToAction("Detail", "Challenge", new { mod = Module.ModulId, id = objchallenge.Entity.ContentId }));
            }
        }