public ActionResult ConfirmMail(Guid UID)
 {
     try
     {
         TAC_User user = new TAC_User();
         if (Request.QueryString.Count > 0 && Request.QueryString.Keys[0] == "UID")
         {
             var CurrentUser = db.TAC_User.Find(UID);
             CurrentUser.RepeatPassword = CurrentUser.UPassword;
             CurrentUser.IsVerified     = true;
             db.TAC_User.Attach(CurrentUser);
             var entry = db.Entry(CurrentUser);
             entry.Property(e => e.IsVerified).IsModified = true;
             db.SaveChanges();
             return(RedirectToAction("Login", "Login"));
         }
     }
     catch (Exception ex)
     {
         ViewBag.Error = "This Link is Invalid";
         Console.WriteLine(ex.InnerException);
         throw;
     }
     return(View());
 }
        public ActionResult DeleteConfirmed(Guid id)
        {
            TAC_User tAC_User = db.TAC_User.Find(id);

            db.TAC_User.Remove(tAC_User);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "UserId,Email,UPassword,First_Name,Last_Name,Gender,DOB,Address1,Address2,City,State,Country,Phone,IsVerified,IsLocked,IsActive,CreatedDate")] TAC_User tAC_User)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tAC_User).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Country = new SelectList(db.TAC_Country, "CountryId", "CountryName", tAC_User.Country);
     ViewBag.Country = new SelectList(db.TAC_Country, "CountryId", "CountryName", tAC_User.Country);
     return(View(tAC_User));
 }
        // GET: Admin/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TAC_User tAC_User = db.TAC_User.Find(id);

            if (tAC_User == null)
            {
                return(HttpNotFound());
            }
            return(View(tAC_User));
        }
        // GET: Admin/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TAC_User tAC_User = db.TAC_User.Find(id);

            if (tAC_User == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Country = new SelectList(db.TAC_Country, "CountryId", "CountryName", tAC_User.Country);
            ViewBag.Country = new SelectList(db.TAC_Country, "CountryId", "CountryName", tAC_User.Country);
            return(View(tAC_User));
        }
        //public ActionResult Index1()
        //{

        //    return View(ClassifiedApi.GetAllPosts());
        //}

        // GET: Classified/Create
        public ActionResult PostAd(int?categoryID)
        {
            Session["categoryID"] = categoryID;

            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }

            PostAdModel postAdModel = new PostAdModel();

            postAdModel.User = new TAC_ClassifiedContact();
            TAC_User model  = (TAC_User)Session["User"];
            var      record = dbContext.TAC_User.Find(model.UserId);

            postAdModel.User.ContactName  = record.First_Name + " " + record.Last_Name;
            postAdModel.User.ContactPhone = record.Phone;
            postAdModel.User.ContactCity  = record.City;
            return(View(postAdModel));
        }
        public void SendMail(TAC_User user)
        {
            try
            {
                StringBuilder sbEmailBody = new StringBuilder();
                sbEmailBody.Append("Dear " + user.First_Name + ",<br/><br/>");
                sbEmailBody.Append("Please click on the following link to activate your account");
                sbEmailBody.Append("<br/>");
                sbEmailBody.Append("http://www.taclassifieds.com/Register/ConfirmMail?UID=" + user.UserId);
                sbEmailBody.Append("<br/><br/>");
                sbEmailBody.Append("<b>TechAspect Solutions</b>");

                HelperClasses.SendEmail obj = new HelperClasses.SendEmail();
                obj.SendEmailMessage(user.Email, sbEmailBody.ToString(), "Account Activation");
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessagee = "Technical Problem while sending an confirmation Email. Please try again.";
            }
        }
 public ActionResult Register(TAC_User user)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var list = db.TAC_User.ToList();
             if (user.TermsAndConditions)
             {
                 if ((list.Where(x => x.Email.Equals(user.Email)).Count() <= 0))
                 {
                     user.UserId      = Guid.NewGuid();
                     user.IsAdmin     = false;
                     user.IsActive    = true;
                     user.IsLocked    = false;
                     user.CreatedDate = DateTime.Now;
                     user.UPassword   = FormsAuthentication.HashPasswordForStoringInConfigFile(user.UPassword, "SHA1");
                     db.TAC_User.Add(user);
                     db.SaveChanges();
                     SendMail(user);
                     return(RedirectToAction("Login", "Login"));
                 }
                 else
                 {
                     ViewBag.ErrorMessage = "Email ID already exists. Please try another one.";
                     //ViewBag.ErrorMessage.ForeColor = System.Drawing.Color.Red;
                 }
             }
             else
             {
                 ViewBag.ErrorMessage = "Please check the Terms and Conditions.";
             }
         }
     }
     catch (Exception ex)
     {
         ViewBag.ErrorMessage = "Technical Problem. Please try again.";
         // ViewBag.ErrorMessage.ForeColor = System.Drawing.Color.Red;
     }
     return(View());
 }
        public ActionResult PostAd(PostAdModel postAdModel, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    postAdModel.Classified.Summary    = postAdModel.Classified.Description;
                    postAdModel.Classified.PostedDate = DateTime.Now;
                    if (Session["User"] != null)
                    {
                        TAC_User model = (TAC_User)Session["User"];
                        postAdModel.Classified.CreatedBy = model.UserId;
                    }
                    else
                    {
                        return(View());
                    }
                    if (Session["categoryID"] != null)
                    {
                        postAdModel.Classified.CategoryId = (int)Session["categoryID"];
                    }
                    else
                    {
                        ModelState.AddModelError("CategoryId", "Please select category");
                        return(View(model: postAdModel));
                    }
                    //fileupload logic
                    if (Request.Files.Count > 0)
                    {
                        int MaxContentLength = 1024 * 1024 * 3; //3 MB
                        var file             = Request.Files[0];

                        if (file != null && file.ContentLength > 0 && file.ContentLength < MaxContentLength)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var path     = Path.Combine(Server.MapPath("../Resources/Uploaded_Images/"), fileName);
                            file.SaveAs(path);
                            postAdModel.Classified.ClassifiedImage = Path.Combine("../Resources/Uploaded_Images/", fileName);
                        }
                        else
                        {
                            if (file.ContentLength > MaxContentLength)
                            {
                                ViewBag.Message = "Please upload an image less 3MB ";
                            }
                        }
                    }

                    dbContext.TAC_Classified.Add(postAdModel.Classified);
                    dbContext.SaveChanges();
                    postAdModel.User.ClassifiedId = postAdModel.Classified.ClassifiedId;
                    dbContext.TAC_ClassifiedContact.Add(postAdModel.User);
                    dbContext.SaveChanges();

                    return(RedirectToAction("MyAccount"));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Sorry, your data was not saved.";
            }
            return(View(postAdModel));
        }
        public ActionResult MyAccount(int?categoryID, int?pageNumber)
        {
            Logs();
            MyAccountModel myAccountModel = new MyAccountModel();
            TAC_User       model          = new TAC_User();

            if (Session["User"] != null)
            {
                model = (TAC_User)Session["User"];
            }
            else
            {
                ModelState.AddModelError("User", "Please Login to continue");
                return(View());
            }

            int totalPageCount = 0;

            myAccountModel.nextButton = 2;
            myAccountModel.prevButton = 1;

            ViewBag.CategoryId = categoryID;
            int pageSize       = 3;
            var lstClassifieds = new List <MyAccountClassifieds>();
            int pagecount      = 0;

            if (pageNumber == null || pageNumber == 1)
            {
                pageNumber = 1;
                myAccountModel.nextButton = 2; myAccountModel.prevButton = 1;
            }
            if (categoryID == null)
            {
                lstClassifieds = GetMyAccountClassifiedFromPosts(ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList()).OrderBy(x => x.PostedDate).Skip(((int)pageNumber - 1) * pageSize).Take((int)pageSize).ToList();
                pagecount      = (int)Math.Ceiling((decimal)ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList().Count / (decimal)pageSize);
            }
            else
            {
                lstClassifieds = GetMyAccountClassifiedFromPosts(ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList()).Where(x => x.CategoryId == categoryID).OrderBy(x => x.PostedDate).Skip(((int)pageNumber - 1) * pageSize).Take((int)pageSize).ToList();
                pagecount      = (int)Math.Ceiling((decimal)ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList().Where(x => x.CategoryId == categoryID).ToList().Count / (decimal)pageSize);
            }
            //if (lstClassifieds.Count % 3 == 0)
            //{
            //    totalPageCount = lstClassifieds.Count / 3;
            //}
            //else
            //{
            //    totalPageCount = (lstClassifieds.Count / 3) + 1;
            //}

            if (pageNumber == pagecount)
            {
                myAccountModel.nextButton = pagecount;
                if (pagecount == 1)
                {
                    myAccountModel.prevButton = 1;
                }
                else
                {
                    myAccountModel.prevButton = Convert.ToInt32(pageNumber) - 1;
                }
            }
            else
            {
                myAccountModel.nextButton = Convert.ToInt32(pageNumber) + 1;
                if (pageNumber == 1)
                {
                    myAccountModel.prevButton = Convert.ToInt32(pageNumber);
                }
                else
                {
                    myAccountModel.prevButton = Convert.ToInt32(pageNumber) - 1;
                }
            }


            myAccountModel.myAccountClassifieds = lstClassifieds;
            myAccountModel.pageCount            = pagecount;
            myAccountModel.lstCategory          = ClassifiedApi.GetAllCategory();
            return(View(myAccountModel));
        }