Example #1
0
        public ActionResult LoginCompletition(Konsumator konsumator)
        {
            bool               flag = false;
            Konsumator         kons = new Konsumator();
            KonsumatorDbClient konsumatorDbClient = new KonsumatorDbClient();

            try
            {
                flag = konsumatorDbClient.CheckLogin(konsumator);
                if (flag == true)
                {
                    kons = konsumatorDbClient.GetLoginSession(konsumator);
                    Session["Perdorues"] = kons;
                    Konsumator konsumues = (Konsumator)Session["Perdorues"];
                    ViewBag.ErrorMessage = "Login u krye me sukses! " + "Welcome, " + konsumues.UserName;
                    if (Session["Action"] != null && Session["Controller"] != null)
                    {
                        return(RedirectToAction((String)Session["Action"], (String)Session["Controller"]));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Login deshtoi! ";
                }
            }
            catch (SqlException ex)
            {
                ViewBag.ErrorMessage = "Something went wrong ! " + ex.StackTrace;
            }
            return(View());
        }
        public ActionResult InsertAddress(FormCollection collection)
        {
            if (Session["Perdorues"] != null)
            {
                Konsumator kons       = (Konsumator)Session["Perdorues"];
                int        id         = kons.IdKonsumator;
                String     rrugeEmer  = collection["rrugeTxt"];
                int        ndertese   = Convert.ToInt32(collection["nderteseTxt"]);
                int        shkalle    = Convert.ToInt32(collection["shkalleTxt"]);
                int        apartament = Convert.ToInt32(collection["apartamentTxt"]);
                int        shtetid    = Convert.ToInt32(collection["shtetiTxt"]);
                int        qytetId    = Convert.ToInt32(collection["qytetiTxt"]);
                int        zipCode    = Convert.ToInt32(collection["ziptTxt"]);

                Adrese adrese = new Adrese(rrugeEmer, ndertese, shkalle, apartament, shtetid, qytetId, zipCode);

                try
                {
                    KonsumatorDbClient consDbClient = new KonsumatorDbClient();
                    consDbClient.AddAdress(id, adrese);
                    return(Json(new { status = "success", message = "address added!" }));
                }
                catch (Exception ex)
                {
                    return(Json(new { status = "error", message = "something went wrong! " + ex.Message }));
                }
            }
            else
            {
                Session["Action"]     = "AddAddress";
                Session["Controller"] = "Profiles";
                return(RedirectToAction("LoginForm", "Login"));
            }
        }
        public ActionResult UploadPicture(HttpPostedFileBase file)
        {
            try
            {
                Photo      foto      = new Photo();
                Konsumator kons      = (Konsumator)Session["Perdorues"];
                string     fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                string     extension = Path.GetExtension(file.FileName);
                fileName            = fileName + extension;
                foto.profilePicPath = "~/Images/" + fileName;
                fileName            = Path.Combine(Server.MapPath("~/Images/"), fileName);
                foto.profilePicName = fileName;
                file.SaveAs(fileName);
                KonsumatorDbClient client = new KonsumatorDbClient();
                client.UpdatePicture(kons.IdKonsumator, foto);
                ViewBag.ErroMessage = "Picture updated!";

                return(Json(new { data = new  { status = "success", message = "Picture updated!" } }));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "Something went wrong! " + ex.Message;
                return(Json(new { data = new  { status = "error", message = "Something went wrong! " + ex.Message } }));
            }
        }
        public ActionResult UserRegisterCompletition(Photo image)
        {
            try
            {
                try
                {
                    string fileName  = Path.GetFileNameWithoutExtension(image.ImageFile.FileName);
                    string extension = Path.GetExtension(image.ImageFile.FileName);
                    fileName             = fileName + extension;
                    image.profilePicPath = "~/Images/" + fileName;
                    fileName             = Path.Combine(Server.MapPath("~/Images/"), fileName);
                    image.ImageFile.SaveAs(fileName);
                    KonsumatorDbClient consumatorDbClient = new KonsumatorDbClient();
                    consumatorDbClient.Insert((Konsumator)TempData["konsumator"], image);
                    ViewBag.ErrorMessage = "User registered successfully with profile picture!";
                }
                catch (NullReferenceException ex)
                {
                    KonsumatorDbClient consumatorDbClient = new KonsumatorDbClient();
                    consumatorDbClient.InsertWithoutPhoto((Konsumator)TempData["konsumator"]);
                    ViewBag.ErrorMessage = "User registered successfully! Without profile picture! " + ex.Message;
                }
            }
            catch (SqlException ex)
            {
                ViewBag.ErrorMessage = "Something went wrong! " + ex.Message;
            }


            return(View());
        }
        public ActionResult MyProfile()
        {
            if (Session["Perdorues"] != null)
            {
                Konsumator kons = new Konsumator();
                try
                {
                    kons = (Konsumator)Session["Perdorues"];

                    KonsumatorDbClient    konsumatorClient = new KonsumatorDbClient();
                    KonsumatorWithPicture konsumator       = konsumatorClient.GetKonsumatorById(kons.IdKonsumator);
                    ViewBag.Data = konsumator;

                    if (konsumator.picture.profilePicPath == "")
                    {
                        ViewBag.Src = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT6CgVGg5OjY7d64jvpXLs4MsWpykLmzOa_I6ClH2zLvycZ5J2c4g";
                    }
                    else
                    {
                        ViewBag.Src = konsumator.picture.profilePicPath;
                    }

                    SearchOperations ops   = new SearchOperations();
                    List <Prone>     prona = ops.GetByUserId(kons.IdKonsumator);
                    ViewBag.Properties = prona;
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMessage = kons.IdKonsumator + "Something went wrong! " + ex.Message;
                }
            }
            else
            {
                Session["Action"]     = "MyProfile";
                Session["Controller"] = "Profiles";
                return(RedirectToAction("LoginForm", "Login"));
            }

            return(View());
        }
        public ActionResult CreditCardInsertion(FormCollection collection)
        {
            if (Session["Perdorues"] != null)
            {
                try
                {
                    Konsumator kon        = (Konsumator)Session["Perdorues"];
                    int        id         = kon.IdKonsumator;
                    String     cardHolder = collection["cardHolderTxt"];
                    String     cardNumber = collection["cardNumberTxt"];
                    String     month      = collection["monthTxt"];
                    String     year       = collection["yearTxt"];
                    string     date       = "01/" + month + "/" + year;

                    DateTime dateDb  = Convert.ToDateTime(date);
                    String   secCode = collection["securityCodeTxt"];
                    String   zipcode = collection["zipCodeTxt"];

                    CreditCard card = new CreditCard(cardHolder, cardNumber, dateDb, secCode, zipcode);

                    KonsumatorDbClient dbClient = new KonsumatorDbClient();
                    dbClient.AddCreditCard(id, card);

                    return(Json(new { status = "success", message = "credit card inserted!" }));
                }
                catch (Exception ex)
                {
                    return(Json(new { status = "failed", message = "something went wrong! " + ex.Message }));
                }
            }
            else
            {
                Session["Action"]     = "CreditCardInsertion";
                Session["Controller"] = "Profiles";
                return(RedirectToAction("LoginForm", "Login"));
            }
        }