Ejemplo n.º 1
0
        public JsonResult JoinChallenge(int contentId)
        {
            bool result = true;

            SessionCustom.Begin();

            ChaellengeFollowerRepository follower = new ChaellengeFollowerRepository(SessionCustom);

            follower.Entity.ChallengeId = contentId;
            follower.Entity.UserId      = ((CustomPrincipal)User).UserId;
            follower.Entity.Date        = DateTime.Now;
            follower.Insert();
            follower.Entity             = new Domain.Entities.ChaellengeFollower();
            follower.Entity.ChallengeId = contentId;
            int total = follower.GetAll().Count;

            ChallengeRepository challenge = new ChallengeRepository(SessionCustom);

            challenge.Entity.ContentId = contentId;
            challenge.Entity.Followers = total;
            challenge.Update();

            SessionCustom.Commit();

            Business.UserRelation.SaveRelationAction(((CustomPrincipal)User).UserId, null, contentId, "follow", this.SessionCustom);

            return(this.Json(new { result = result }));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public void Validate(IChallenge challenge)
        {
            if (challenge.Status == ChallengeStatus.Pending)
            {
                challenge.Status = ChallengeStatus.Processing;
                ChallengeRepository.Update(challenge);

                Logger.Info("Challenge {id} status updated to {status}", challenge.Id, challenge.Status);

                Task
                .Run(() =>
                {
                    // validate challenge
                    switch (challenge.Type)
                    {
                    case "http-01":
                        ValidateHttpChallenge(challenge);
                        break;

                    default:
                        throw new Exception($"Unsupported Challenge type '{challenge.Type}'");
                    }
                })
                .ContinueWith(t =>
                {
                    // Fault validate
                    if (t.IsFaulted)
                    {
                        Error err              = t.Exception.InnerException;
                        challenge.Error        = ChallengeRepository.CreateError();
                        challenge.Error.Detail = err.Detail;
                        challenge.Error.Type   = err.Type;
                        challenge.Status       = ChallengeStatus.Invalid;
                        ChallengeRepository.Update(challenge);
                    }

                    //Complete validate
                    if (t.IsCompleted)
                    {
                        if (challenge.Status == ChallengeStatus.Processing)
                        {
                            challenge.Status    = ChallengeStatus.Valid;
                            challenge.Validated = DateTime.UtcNow;
                            ChallengeRepository.Update(challenge);
                        }
                    }

                    Logger.Info("Challenge {id} status updated to {status}", challenge.Id, challenge.Status);
                });
            }
            else
            {
                throw new MalformedException("Wrong challenge status");
            }
        }
Ejemplo n.º 3
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 }));
            }
        }