public ActionResult ArticlePublishedOption(int articleid)
        {
            ArticleViewModel articleVM   = null;
            ArticleItem      articleItem = null;
            DataAccessLayer  datalayer   = null;
            List <TagItem>   tags        = null;

            //Guid userId;

            articleVM = new ArticleViewModel();

            if (Session["UserProfile"] != null)
            {
                UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                //articleVM.Userprofile = userprofile;
                //userId = userprofile.ID;

                datalayer   = new DataAccessLayer();
                articleItem = datalayer.GetArticlePublishedDetails(articleid, userprofile.ID);

                if (articleItem != null)
                {
                    articleVM.ArticleItem = articleItem;

                    if (!string.IsNullOrEmpty(articleItem.Tag_Article))
                    {
                        tags = new List <TagItem>();
                        var tagSplit = articleItem.Tag_Article.Split(',');
                        for (var i = 0; i < tagSplit.Length - 1; i++)
                        {
                            TagItem tagitem = new TagItem {
                                id = i, name = tagSplit[i]
                            };
                            tags.Add(tagitem);
                        }
                        articleVM.ArticleItem.Tags = tags;
                    }
                }
                else
                {
                    articleVM             = new ArticleViewModel();
                    articleVM.ArticleItem = new ArticleItem();
                    ModelState.AddModelError("", "Article Not Exist or Some error occured while fetching article details.");
                    StringBuilder script = new StringBuilder();
                    script.Append("<script type='text/javascript'>");
                    script.Append("$('#error_alert').show();");
                    script.Append("</script>");
                    ViewBag.StartScript = script.ToString();
                    return(View(articleVM));
                }
            }
            else
            {
                return(RedirectToAction("Authenticate", "Account"));
            }


            return(View(articleVM));
        }
示例#2
0
    public static void ProfileModifySelfUserProfile()
    {
        UserProfileItem param = new UserProfileItem();

        param.user_profile_item_level = 10;
        TIMResult res = TencentIMSDK.ProfileModifySelfUserProfile(param, addAsyncDataToConsole);

        addDataToConsole(res);
    }
        public ActionResult ArticleOption(int articleid)
        {
            ArticleViewModel articleVM   = null;
            ArticleItem      articleItem = null;
            DataAccessLayer  datalayer   = null;
            List <TagItem>   tags        = null;

            //Guid userId;

            articleVM = new ArticleViewModel();

            if (Session["UserProfile"] != null)
            {
                UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                //articleVM.Userprofile = userprofile;
                //userId = userprofile.ID;

                datalayer   = new DataAccessLayer();
                articleItem = datalayer.GetArticleEntryDetails(articleid, userprofile.ID);

                if (articleItem != null)
                {
                    articleVM.ArticleItem = articleItem;

                    if (!string.IsNullOrEmpty(articleItem.Tag_Article))
                    {
                        tags = new List <TagItem>();
                        var tagSplit = articleItem.Tag_Article.Split(',');
                        for (var i = 0; i < tagSplit.Length - 1; i++)
                        {
                            TagItem tagitem = new TagItem {
                                id = i, name = tagSplit[i]
                            };
                            tags.Add(tagitem);
                        }
                        articleVM.ArticleItem.Tags = tags;
                    }
                }
                else
                {
                    articleVM             = new ArticleViewModel();
                    articleVM.ArticleItem = new ArticleItem();
                    ModelState.AddModelError("", "Article Not Exist or Some error occured while fetching article details.");
                    return(View(articleVM));
                }
            }
            else
            {
                return(RedirectToAction("Authenticate", "Account"));
            }


            return(View(articleVM));
        }
示例#4
0
        public ActionResult EditForm(int?id)
        {
            var obj = new UserProfileItem();

            var list = userRepository.GetListForTree <object>();

            if (id.HasValue)
            {
                obj = userRepository.GetItemById <UserProfileItem>(id.Value);
            }

            return(Json(new
            {
                data = obj,
                list = list
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Archive(int articleid)
        {
            DataAccessLayer datalayer = null;

            if (Session["UserProfile"] != null)
            {
                UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                datalayer = new DataAccessLayer();
                bool isArchived = datalayer.ArchiveArticle(articleid, userprofile.ID, userprofile.Role);
                if (!isArchived)
                {
                    //some error occured while article archival
                    //rediredct to error page
                }
                return(RedirectToAction("Index", "Manage"));
            }
            else
            {
                return(RedirectToAction("Authenticate", "Account"));
            }
        }
        public async Task <bool> UpdateProfileAsync(string userId, UserProfileItem item)
        {
            if (!ObjectId.TryParse(userId, out ObjectId Id))
            {
                throw new FormatException("UserId did not have excepted format.");
            }

            var filter = Builders <UserEntity> .Filter.Eq(x => x.Id, Id);

            var update = Builders <UserEntity> .Update
                         .Set(x => x.Version, DateTime.UtcNow.Ticks);

            if (!string.IsNullOrEmpty(item.FirstName))
            {
                update = update.Set(x => x.FirstName, item.FirstName);
            }
            if (!string.IsNullOrEmpty(item.LastName))
            {
                update = update.Set(x => x.LastName, item.LastName);
            }

            if (item.DateOfBirth.HasValue)
            {
                update = update.Set(x => x.DateOfBirth, new DateTime(item.DateOfBirth.Value.Year, item.DateOfBirth.Value.Month, item.DateOfBirth.Value.Day, 0, 0, 0, DateTimeKind.Utc));
            }

            if (!string.IsNullOrEmpty(item.City))
            {
                update = update.Set(x => x.City, item.City);
            }
            if (!string.IsNullOrEmpty(item.ProfileImageUrl))
            {
                update = update.Set(x => x.ProfileImageUrl, item.ProfileImageUrl);
            }

            var ret = await _context.UserEntityCollection.UpdateOneAsync(filter, update);

            return(ret.MatchedCount > 0);
        }
        public ActionResult EditPublished(ArticleViewModel articleVM, FormCollection formValues, string command)
        {
            DataAccessLayer     datalayer          = null;
            List <CategoryItem> article_categories = null;

            if (command == "Save & Preview")
            {
                if (ModelState.IsValid)
                {
                    if (Session["UserProfile"] != null)
                    {
                        List <TagItem> tags = null;

                        UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                        articleVM.ArticleItem.Userid = userprofile.ID;
                        string articleID = articleVM.ArticleItem.ID.ToString();
                        if (!string.IsNullOrEmpty(articleID))
                        {
                            if (!string.IsNullOrEmpty(articleVM.ArticleItem.Content))
                            {
                                articleVM.ArticleItem.Content_summary = StringHtmlExtensions.TruncateHtml(articleVM.ArticleItem.Content, CONTENT_SUMMARY_LENGTH, "....");
                            }

                            if (!string.IsNullOrEmpty(articleVM.ArticleItem.Title_English))
                            {
                                articleVM.ArticleItem.Title_SEO = articleVM.ArticleItem.Title_English.ToSeoUrl();
                            }


                            //update the article entry

                            datalayer = new DataAccessLayer();
                            if (datalayer.UpdateArticlePublished(articleVM.ArticleItem))
                            {
                                if (!string.IsNullOrEmpty(articleVM.ArticleItem.Tag_Article))
                                {
                                    //update tag table for this article
                                    tags = new List <TagItem>();
                                    var tagSplit = articleVM.ArticleItem.Tag_Article.Split(',');
                                    for (var i = 0; i < tagSplit.Length - 1; i++)
                                    {
                                        TagItem tagitem = new TagItem {
                                            id = i, name = tagSplit[i]
                                        };
                                        tags.Add(tagitem);
                                    }
                                    bool istagsupdated = datalayer.UpdateTagEntry(tags, articleVM.ArticleItem.ID);
                                    if (!istagsupdated)
                                    {
                                        //log error that tag updation failed
                                    }
                                }

                                return(RedirectToAction("ArticlePublishedOption", "Manage", new { articleid = articleID }));
                            }
                            else
                            {
                                //some error occured in updation - redirect to error page
                            }
                        }
                    }
                    else
                    {
                        return(RedirectToAction("Authenticate", "Account"));
                    }
                }
            }
            else if (command == "Cancel")
            {
                return(RedirectToAction("Index", "Manage"));
            }
            //TODO: Lot of work need to be done here for error handling, tags etc
            datalayer            = new DataAccessLayer();
            article_categories   = datalayer.GetCategories();
            articleVM.Categories = article_categories;
            StringBuilder script = new StringBuilder();

            script.Append("<script type='text/javascript'>");
            script.Append("$('#" + articleVM.ArticleItem.Category.Id + "').prop('checked', true);");
            //script.Append("$('#error_alert').show();");
            script.Append("</script>");
            ViewBag.StartScript = script.ToString();

            return(View(articleVM));
        }
        public ActionResult EditPublished(int articleid)
        {
            ArticleViewModel    ArticleVM          = null;
            DataAccessLayer     datalayer          = null;
            ArticleItem         articleItem        = null;
            List <CategoryItem> article_categories = null;

            Guid userId;

            if (Session["UserProfile"] != null)
            {
                UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                userId = userprofile.ID;

                datalayer   = new DataAccessLayer();
                articleItem = datalayer.GetArticlePublishedDetails(articleid, userId);

                if (articleItem != null)
                {
                    ArticleVM             = new ArticleViewModel();
                    ArticleVM.ArticleItem = articleItem;

                    article_categories   = datalayer.GetCategories();
                    ArticleVM.Categories = article_categories;
                    string newtagstr = string.Empty;
                    if (!string.IsNullOrEmpty(articleItem.Tag_Article))
                    {
                        var tagSplit = articleItem.Tag_Article.Split(',');
                        newtagstr = "[";
                        for (var i = 0; i < tagSplit.Length - 1; i++)
                        {
                            newtagstr = newtagstr + "'" + tagSplit[i] + "',";
                        }
                        newtagstr = newtagstr.TrimEnd(',') + "]";
                    }
                    //ArticleVM.ArticleItem.Tag_Article = newtagstr;

                    ViewBag.HdnSelectedTags = newtagstr;

                    StringBuilder script = new StringBuilder();
                    script.Append("<script type='text/javascript'>");
                    script.Append("$('#" + articleItem.Category.Id + "').prop('checked', true);");
                    script.Append("</script>");
                    ViewBag.StartScript = script.ToString();
                    return(View(ArticleVM));
                }
                else
                {
                    ArticleVM             = new ArticleViewModel();
                    ArticleVM.ArticleItem = new ArticleItem();
                    ModelState.AddModelError("", "Article Not Exist or Some error occured while fetching article details.");
                    StringBuilder script = new StringBuilder();
                    script.Append("<script type='text/javascript'>");
                    script.Append("$('#error_alert').show();");
                    script.Append("</script>");
                    ViewBag.StartScript = script.ToString();
                    return(View(ArticleVM));
                }
            }
            else
            {
                return(RedirectToAction("Authenticate", "Account"));
            }
        }
        public ActionResult Edit(ArticleViewModel articleVM, FormCollection formValues, string command)
        {
            if (command == "Save & Preview")
            {
                if (ModelState.IsValid)
                {
                    if (Session["UserProfile"] != null)
                    {
                        List <TagItem> tags = null;

                        UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                        articleVM.ArticleItem.Userid = userprofile.ID;
                        string articleID = articleVM.ArticleItem.ID.ToString();
                        if (!string.IsNullOrEmpty(articleID))
                        {
                            if (!string.IsNullOrEmpty(articleVM.ArticleItem.Content))
                            {
                                articleVM.ArticleItem.Content_summary = StringHtmlExtensions.TruncateHtml(articleVM.ArticleItem.Content, CONTENT_SUMMARY_LENGTH, "....");
                            }

                            if (!string.IsNullOrEmpty(articleVM.ArticleItem.Title_English))
                            {
                                articleVM.ArticleItem.Title_SEO = articleVM.ArticleItem.Title_English.ToSeoUrl();
                            }


                            //update the article entry
                            DataAccessLayer datalayer = null;
                            datalayer = new DataAccessLayer();
                            if (datalayer.UpdateArticleEntry(articleVM.ArticleItem))
                            {
                                if (!string.IsNullOrEmpty(articleVM.ArticleItem.Tag_Article))
                                {
                                    //update tag table for this article
                                    tags = new List <TagItem>();
                                    var tagSplit = articleVM.ArticleItem.Tag_Article.Split(',');
                                    for (var i = 0; i < tagSplit.Length - 1; i++)
                                    {
                                        TagItem tagitem = new TagItem {
                                            id = i, name = tagSplit[i]
                                        };
                                        tags.Add(tagitem);
                                    }
                                    bool istagsupdated = datalayer.UpdateTagEntry(tags, articleVM.ArticleItem.ID);
                                    if (!istagsupdated)
                                    {
                                        //log error that tag updation failed
                                    }
                                }

                                return(RedirectToAction("ArticleOption", "Manage", new { articleid = articleID }));
                            }
                            else
                            {
                                //some error occured in updation - redirect to error page
                            }
                        }
                    }
                    else
                    {
                        return(RedirectToAction("Authenticate", "Account"));
                    }
                }
            }
            else if (command == "Cancel")
            {
                return(RedirectToAction("Index", "Manage"));
            }
            return(View(articleVM));
        }
        public ActionResult ArticlePublishedOption(ArticleViewModel articleVM, FormCollection formValues, string command, HttpPostedFileBase uplimage)
        {
            DataAccessLayer datalayer       = null;
            ArticleItem     articleItem     = null;
            Guid            valid_Articleid = Guid.Empty;
            StringBuilder   script          = null;

            //Guid userId;

            if (Session["UserProfile"] != null)
            {
                UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                // userId = userprofile.ID;

                if (command == "Previous Step")
                {
                    return(RedirectToAction("EditPublished", "Manage", new { articleid = articleVM.ArticleItem.ID }));
                }
                else if (command == "Publish")
                {
                    datalayer = new DataAccessLayer();
                    if (datalayer.SubmitPublishedArticle(articleVM.ArticleItem, userprofile.ID, userprofile.Role))
                    {
                        return(RedirectToAction("Index", "Manage"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Error while publishing the article");
                        datalayer             = new DataAccessLayer();
                        articleItem           = datalayer.GetArticlePublishedDetails(articleVM.ArticleItem.ID, userprofile.ID);
                        articleVM.ArticleItem = articleItem;

                        script = new StringBuilder();
                        script.Append("<script type='text/javascript'>");
                        script.Append("  $('#error_alert').fadeIn(350, function ());");
                        script.Append("</script>");

                        ViewBag.StartScript = script.ToString();

                        return(View(articleVM));
                    }
                }
                else if (command == "Upload")
                {
                    if (uplimage == null)
                    {
                        ModelState.AddModelError("", "You didn't select an image file or the file you uploaded was invalid!");
                        datalayer             = new DataAccessLayer();
                        articleItem           = datalayer.GetArticlePublishedDetails(articleVM.ArticleItem.ID, userprofile.ID);
                        articleVM.ArticleItem = articleItem;

                        script = new StringBuilder();
                        script.Append("<script type='text/javascript'>");
                        script.Append("  $('#error_alert').fadeIn(350, function () { $('#uplimage').focus(); });");
                        script.Append("</script>");

                        ViewBag.StartScript = script.ToString();

                        return(View(articleVM));
                    }
                    else
                    {
                        var result = Helper_Magazine.UploadImage(uplimage, HttpContext.Server, articleVM.ArticleItem.ID, "published");

                        if (!result.Errors.Any())
                        {
                            articleVM.ArticleItem.Image_path = result.ImagePath;
                            return(RedirectToAction("ArticlePublishedOption", "Manage", new { articleid = articleVM.ArticleItem.ID.ToString() }));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Error while uploading image!");
                            articleVM.Errors      = result.Errors;
                            datalayer             = new DataAccessLayer();
                            articleItem           = datalayer.GetArticlePublishedDetails(articleVM.ArticleItem.ID, userprofile.ID);
                            articleVM.ArticleItem = articleItem;

                            script = new StringBuilder();
                            script.Append("<script type='text/javascript'>");
                            script.Append("  $('#error_alert').fadeIn(350, function () { $('#uplimage').focus(); });");
                            script.Append("</script>");

                            ViewBag.StartScript = script.ToString();

                            return(View(articleVM));
                        }
                    }
                }
                else if (command == "Delete")
                {
                    var result = Helper_Magazine.DeleteImage(HttpContext.Server, articleVM.ArticleItem.ID, "published");
                    if (!result.Errors.Any())
                    {
                        return(RedirectToAction("ArticlePublishedOption", "Manage", new { articleid = articleVM.ArticleItem.ID.ToString() }));
                    }
                    else
                    {
                        //some error occured while deleting the image
                        ModelState.AddModelError("", "Error while deleting image!");
                        articleVM.Errors = result.Errors;

                        script = new StringBuilder();
                        script.Append("<script type='text/javascript'>");
                        script.Append("  $('#error_alert').fadeIn(350, function () { $('#uplimage').focus(); });");
                        script.Append("</script>");

                        ViewBag.StartScript = script.ToString();

                        return(View(articleVM));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Authenticate", "Account"));
            }


            return(View(articleVM));
        }
        public ActionResult Index()
        {
            DataAccessLayer       datalayer         = null;
            List <ArticleItem>    articlesEntry     = null;
            List <ArticleItem>    articlesPublished = null;
            List <ArticleItem>    articlesArchived  = null;
            DashboardViewModel    dashboardVM       = null;
            List <NewsItem>       breakingNewsItems = null;
            List <LatestNewsItem> latestTenNews     = null;


            if (Session["userprofile"] != null)
            {
                UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];

                dashboardVM            = new DashboardViewModel();
                dashboardVM.userDetail = userprofile;

                datalayer = new DataAccessLayer();

                // get all articles entry
                articlesEntry = datalayer.GetAllArticlesEntry(userprofile.ID, userprofile.Role);
                if (articlesEntry == null)
                {
                    articlesEntry = new List <ArticleItem>();
                }
                dashboardVM.ArticleEntryItems = articlesEntry;


                // get all articles published
                articlesPublished = datalayer.GetAllArticlesPublished(userprofile.ID, userprofile.Role);
                if (articlesPublished == null)
                {
                    articlesPublished = new List <ArticleItem>();
                }
                dashboardVM.ArticlePublishedItems = articlesPublished;


                // get all articles Archived
                articlesArchived = datalayer.GetAllArticlesArchived(userprofile.ID, userprofile.Role);;
                if (articlesArchived == null)
                {
                    articlesArchived = new List <ArticleItem>();
                }
                dashboardVM.ArticleArchivedItems = articlesArchived;



                if (dashboardVM.userDetail.Role == "admin" || dashboardVM.userDetail.Role == "ceditor" || dashboardVM.userDetail.Role == "sadmin")
                {   // 1-  get all catagories
                    List <CategoryItem> article_categories = datalayer.GetCategories();
                    dashboardVM.Categories = article_categories;

                    // 2 - get all user profiles
                    List <UserProfileItem> UserProfiles = datalayer.GetAllUsers(userprofile.Role);

                    List <string> roles = new List <string>();

                    if (dashboardVM.userDetail.Role == "sadmin")
                    {
                        roles.Add("sadmin"); roles.Add("admin"); roles.Add("ceditor"); roles.Add("editor"); roles.Add("newuser");
                    }
                    else if (dashboardVM.userDetail.Role == "admin")
                    {
                        roles.Add("admin"); roles.Add("ceditor"); roles.Add("editor"); roles.Add("newuser");
                    }
                    else if (dashboardVM.userDetail.Role == "ceditor")
                    {
                        roles.Add("ceditor"); roles.Add("editor"); roles.Add("newuser");
                    }



                    foreach (UserProfileItem item in UserProfiles)
                    {
                        item.Roles = new List <SelectListItem>();
                        foreach (string role in roles)
                        {
                            SelectListItem selectListItem = new SelectListItem {
                                Text = role, Value = role, Selected = role == item.Role
                            };
                            item.Roles.Add(selectListItem);
                        }
                    }
                    dashboardVM.UserProfiles = UserProfiles;


                    // 3- get breaking news
                    breakingNewsItems = datalayer.GetBreakingNews();

                    //bind drop down with top 10 latest news
                    latestTenNews = datalayer.GetLatestTenNews();

                    foreach (NewsItem newsitem in breakingNewsItems)
                    {
                        newsitem.TopNewsDdl = new List <SelectListItem>();
                        foreach (LatestNewsItem item in latestTenNews)
                        {
                            SelectListItem selectListItem = new SelectListItem {
                                Text = item.title, Value = item.id.ToString(), Selected = item.id == newsitem.Article_id
                            };
                            newsitem.TopNewsDdl.Add(selectListItem);
                        }
                    }



                    dashboardVM.BreakingNews = breakingNewsItems;
                }
            }
            else
            {
                return(RedirectToAction("Authenticate", "Account"));
            }

            return(View(dashboardVM));
        }
        public ActionResult CreateArticle(ArticleViewModel articleVM, FormCollection formValues, string command)
        {
            DataAccessLayer datalayer = null;
            int             articleID = 0;
            List <TagItem>  tags      = null;

            if (command == "Save & Preview")
            {
                if (ModelState.IsValid)
                {
                    //articleVM.ID = Guid.NewGuid();
                    //articleVM.Created_Date = DateTime.Now;
                    if (Session["UserProfile"] != null)
                    {
                        UserProfileItem userprofile = (UserProfileItem)Session["UserProfile"];
                        articleVM.ArticleItem.Userid = userprofile.ID;

                        if (!string.IsNullOrEmpty(articleVM.ArticleItem.Content))
                        {
                            articleVM.ArticleItem.Content_summary = StringHtmlExtensions.TruncateHtml(articleVM.ArticleItem.Content, 200, "....");
                        }
                        if (!string.IsNullOrEmpty(articleVM.ArticleItem.Title_English))
                        {
                            articleVM.ArticleItem.Title_SEO = articleVM.ArticleItem.Title_English.ToSeoUrl();
                        }



                        //TODO: check if content is empty - return VM

                        datalayer = new DataAccessLayer();
                        articleID = datalayer.CreateArticle(articleVM.ArticleItem);
                        if (articleID != 0)
                        {
                            if (!string.IsNullOrEmpty(articleVM.ArticleItem.Tag_Article))
                            {
                                //update tag table for this article
                                tags = new List <TagItem>();
                                var tagSplit = articleVM.ArticleItem.Tag_Article.Split(',');
                                for (var i = 0; i < tagSplit.Length - 1; i++)
                                {
                                    TagItem tagitem = new TagItem {
                                        id = i, name = tagSplit[i]
                                    };
                                    tags.Add(tagitem);
                                }
                                bool istagsupdated = datalayer.UpdateTagEntry(tags, articleID);
                                if (!istagsupdated)
                                {
                                    //log error that tag updation failed
                                }
                            }

                            return(RedirectToAction("ArticleOption", "Manage", new { articleid = articleID }));
                        }
                        else
                        {
                            //some error occured while saving the article
                            return(View(articleVM));
                        }
                    }
                    else
                    {
                        return(RedirectToAction("Authenticate", "Account"));
                    }
                }
            }
            else if (command == "Cancel")
            {
                return(RedirectToAction("Index", "Manage"));
            }

            return(View(articleVM));
        }
示例#13
0
        public ActionResult Authenticate(LogOnModel model, string returnUrl, string command, bool captchaValid, string captchaErrorMessage)
        {
            DataAccessLayer datalayer       = null;
            StringBuilder   script          = null;;
            UserProfileItem userProfileItem = null;

            if (command == "Sign in")
            {
                ModelState["Email_New"].Errors.Clear();
                ModelState["Password_New"].Errors.Clear();
                ModelState["ConfirmPassword_New"].Errors.Clear();
                ModelState["FirstName"].Errors.Clear();
                ModelState["LastName"].Errors.Clear();
                ModelState["Email_Reset"].Errors.Clear();

                if (ModelState.IsValid)
                {
                    datalayer       = new DataAccessLayer();
                    userProfileItem = datalayer.ValidateAndGetUserProfile(model.UserEmail, model.Password);
                    if (userProfileItem != null)
                    {
                        Session["UserProfile"] = userProfileItem;
                        FormsAuthentication.SetAuthCookie(userProfileItem.First_Name + " " + userProfileItem.Last_Name, false);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                            !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Manage"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                        script = new StringBuilder();
                        script.Append("<script type='text/javascript'>");
                        script.Append("$('#validationerror').addClass('alert-warning').show();$('.login-form').show();$('.register-form').hide();$('.forgotpwd-form').hide();");
                        script.Append("</script>");
                        ViewBag.StartScript = script.ToString();
                        model.Password      = string.Empty;
                        return(View(model));
                    }
                }
                else
                {
                    //show validation error

                    script = new StringBuilder();
                    script.Append("<script type='text/javascript'>");
                    script.Append("$('.loginvalidation').show();$('#validationerror').addClass('alert-warning').show();$('.login-form').show();$('.register-form').hide();$('.forgotpwd-form').hide();");
                    script.Append("</script>");
                    ViewBag.StartScript = script.ToString();
                    model.Password      = string.Empty;
                }
            }
            else if (command == "Register")
            {
                ModelState["UserEmail"].Errors.Clear();
                ModelState["Password"].Errors.Clear();
                ModelState["Email_Reset"].Errors.Clear();


                if (ModelState.IsValid)
                {
                    if (captchaValid)
                    {
                        //check if Password and confirm password donot match
                        if (model.Password_New != model.ConfirmPassword_New)
                        {
                            ModelState.AddModelError("", "Password and confirm password donot match.");
                            script = new StringBuilder();
                            script.Append("<script type='text/javascript'>");
                            script.Append("$('#validationerror').addClass('alert-warning').show();$('.register-form').show();$('.login-form').hide();$('.forgotpwd-form').hide();");
                            script.Append("</script>");
                            ViewBag.StartScript       = script.ToString();
                            model.Password_New        = string.Empty;
                            model.ConfirmPassword_New = string.Empty;
                            return(View(model));
                        }

                        datalayer = new DataAccessLayer();
                        //check if User is already registered with मैं हूँ आम आदमी.
                        if (!datalayer.UserEmailExist(model.Email_New))
                        {
                            //create new account
                            bool isNewUserCreated = datalayer.CreateNewUser(model.Email_New, model.Password_New, model.FirstName, model.LastName);
                            if (!isNewUserCreated)
                            {
                                ModelState.AddModelError("", "Error occured while registering your profile. You can contact our support team for more detail.");
                                model.Password_New        = string.Empty;
                                model.ConfirmPassword_New = string.Empty;
                                return(View(model));
                            }
                            else
                            {
                                script = new StringBuilder();
                                script.Append("<script type='text/javascript'>");
                                script.Append("$('#success').addClass('alert-success').show();$('#success').append( '<p><strong>Thank you</strong> for registring on <strong>मैं हूँ आम आदमी </strong><br />We will review and properly direct your application, and someone will be in touch with you shortly.</p>' );$('#success').show();$('#success').delay(5000).fadeOut();");
                                script.Append("</script>");
                                ViewBag.StartScript = script.ToString();
                                model = new LogOnModel();
                                return(View(model));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "User is already registered with मैं हूँ आम आदमी.");
                            script = new StringBuilder();
                            script.Append("<script type='text/javascript'>");
                            script.Append("$('#validationerror').addClass('alert-warning').show();$('.register-form').show();$('.login-form').hide();$('.forgotpwd-form').hide();");
                            script.Append("</script>");
                            ViewBag.StartScript       = script.ToString();
                            model.Password_New        = string.Empty;
                            model.ConfirmPassword_New = string.Empty;
                            return(View(model));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", captchaErrorMessage);
                        script = new StringBuilder();
                        script.Append("<script type='text/javascript'>");
                        script.Append("$('#validationerror').addClass('alert-warning').show();$('.register-form').show();$('.login-form').hide();$('.forgotpwd-form').hide();");
                        script.Append("</script>");
                        ViewBag.StartScript       = script.ToString();
                        model.Password_New        = string.Empty;
                        model.ConfirmPassword_New = string.Empty;
                        return(View(model));
                    }
                }
                else
                {
                    //show validation error

                    script = new StringBuilder();
                    script.Append("<script type='text/javascript'>");
                    script.Append("$('.registervalidation').show();$('#validationerror').addClass('alert-warning').show();$('.register-form').show();$('.login-form').hide();$('.forgotpwd-form').hide();");
                    script.Append("</script>");
                    ViewBag.StartScript       = script.ToString();
                    model.Password_New        = string.Empty;
                    model.ConfirmPassword_New = string.Empty;
                }
            }
            else if (command == "Reset Password")
            {
                ModelState["UserEmail"].Errors.Clear();
                ModelState["Password"].Errors.Clear();
                ModelState["Email_New"].Errors.Clear();
                ModelState["Password_New"].Errors.Clear();
                ModelState["ConfirmPassword_New"].Errors.Clear();
                ModelState["FirstName"].Errors.Clear();
                ModelState["LastName"].Errors.Clear();


                if (ModelState.IsValid)
                {
                    datalayer = new DataAccessLayer();
                    if (datalayer.UserEmailExist(model.UserEmail))
                    {
                        //reset the password and send new password to user email

                        //string newpassword = Helper_Magazine.CreateSalt(8);
                        //if (datalayer.ResetPassword(model.UserEmail, newpassword)) {
                        //    MailMessage messagetouser = new MailMessage();
                        //    messagetouser.Subject = "Main Hun Aam Aadmi - New Password  ---";
                        //    string msgBodyuser = "******" + model.UserEmail + System.Environment.NewLine

                        //        + " We have recieved your request. Find new password as below:-" + System.Environment.NewLine + newpassword
                        //        + " Thanks!" + System.Environment.NewLine
                        //        + "Note: ----system generated mail: Please don't reply----";
                        //    messagetouser.Body = msgBodyuser;
                        //    messagetouser.From = new MailAddress("*****@*****.**");
                        //    messagetouser.To.Add(model.UserEmail);
                        //    messagetouser.IsBodyHtml = true;
                        //    SendMail(messagetouser);
                        script = new StringBuilder();
                        script.Append("<script type='text/javascript'>");
                        script.Append("$('#success').addClass('alert-success').show();$('#success').append( ' <p>You will soon recieve password reset info on your registered email address.</p>' );$('#success').show();$('#success').delay(5000).fadeOut();");
                        script.Append("</script>");
                        ViewBag.StartScript = script.ToString();
                        model = new LogOnModel();
                        return(View(model));
                    }
                    else
                    {
                        ModelState.AddModelError("", "User E-mail address is not registered with मैं हूँ आम आदमी");
                        script = new StringBuilder();
                        script.Append("<script type='text/javascript'>");
                        script.Append("$('#validationerror').addClass('alert-warning').show();$('.forgotpwd-form').show();$('.login-form').hide();$('.register-form').hide();");
                        script.Append("</script>");
                        ViewBag.StartScript = script.ToString();
                        return(View(model));
                    }
                }
                else
                {
                    //show validation error

                    script = new StringBuilder();
                    script.Append("<script type='text/javascript'>");
                    script.Append("$('.forgotpwdvalidation').show();$('#validationerror').addClass('alert-warning').show();$('.forgotpwd-form').show();$('.login-form').hide();$('.register-form').hide();");
                    script.Append("</script>");
                    ViewBag.StartScript = script.ToString();
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }