Exemplo n.º 1
0
        public int Insert(TCredential obj)
        {
            con.Open();
            OracleCommand cmd = con.CreateCommand();

            if (typeof(TCredential) == typeof(BuyerCredential))
            {
                BuyerCredential b = obj as BuyerCredential;

                cmd.CommandText = "insert into buyercredentials values(DEFAULT," + b.BuyerId + ",'" + b.Username + "','" + b.Password + "','active')";
            }

            else if (typeof(TCredential) == typeof(SellerCredential))
            {
                SellerCredential c = obj as SellerCredential;

                cmd.CommandText = "insert into sellercredentials values(DEFAULT," + c.SellerId + ",'" + c.Username + "','" + c.Password + "','active')";
            }

            int result = cmd.ExecuteNonQuery();

            con.Close();

            return(result);
        }
        public ActionResult BuyerLogin(BuyerCredential credential)
        {
            buyerService = Injector.Container.Resolve <ICredentialService <BuyerCredential> >();

            BuyerCredential credentialFromDb = buyerService.ValidateCredential(credential) as BuyerCredential;

            try
            {
                if (credentialFromDb.Status)
                {
                    Session["USERID"] = credentialFromDb.BuyerId;
                    Session["USER"]   = "******";
                    return(RedirectToAction("Index", "Buyer", new { id = credentialFromDb.BuyerId }));
                }

                else
                {
                    return(View("Blocked"));
                }
            }

            catch (Exception)
            {
                return(View("Error"));
            }
        }
Exemplo n.º 3
0
        public Credential GetById(int id)
        {
            con.Open();
            OracleCommand cmd = con.CreateCommand();

            if (typeof(TCredential) == typeof(BuyerCredential))
            {
                BuyerCredential bc = null;

                cmd.CommandText = "select * from buyercredentials where buyerid=" + id;

                OracleDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    bc = new BuyerCredential()
                    {
                        Id = reader.GetInt32(0), BuyerId = reader.GetInt32(1), Username = reader.GetString(2), Password = reader.GetString(3)
                    };
                }

                con.Close();
                return(bc);
            }

            else if (typeof(TCredential) == typeof(SellerCredential))
            {
                SellerCredential sc = null;

                cmd.CommandText = "select * from sellercredentials where sellerid=" + id;

                OracleDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    sc = new SellerCredential()
                    {
                        Id = reader.GetInt32(0), SellerId = reader.GetInt32(1), Username = reader.GetString(2), Password = reader.GetString(3)
                    };
                }

                con.Close();
                return(sc);
            }

            else
            {
                return(null);
            }
        }
        public ActionResult BuyerRegistration(BuyerRegistrationViewModel buyerModel)
        {
            if (ModelState.IsValid)
            {
                Buyer buyer = new Buyer()
                {
                    FirstName = buyerModel.FirstName, LastName = buyerModel.LastName, Gender = buyerModel.Gender, Email = buyerModel.Email, Phone = buyerModel.Phone, Address = buyerModel.Address, AreaId = Convert.ToInt32(buyerModel.AreaId)
                };

                if (buyerService.Insert(buyer) == 1)
                {
                    buyer.Id = buyerService.GetLastBuyerId(buyer);
                    BuyerCredential credential = new BuyerCredential()
                    {
                        Username = buyerModel.Username, Password = buyerModel.Password, BuyerId = buyer.Id, Status = true
                    };

                    if (buyerCredentialService.Insert(credential) == 1)
                    {
                        return(RedirectToAction("Index", "Login", new { id = 1 }));
                    }

                    else
                    {
                        return(View("Error"));
                    }
                }

                else
                {
                    return(View("Error"));
                }
            }

            else
            {
                return(View(buyerModel));
            }
        }
Exemplo n.º 5
0
        public int UpdatePassword(TCredential obj)
        {
            con.Open();
            OracleCommand cmd = con.CreateCommand();

            if (typeof(TCredential) == typeof(BuyerCredential))
            {
                BuyerCredential bc = obj as BuyerCredential;

                cmd.CommandText = "update buyercredentials set password='******' where id=" + bc.Id;

                int result = cmd.ExecuteNonQuery();

                con.Close();

                return(result);
            }

            else if (typeof(TCredential) == typeof(SellerCredential))
            {
                SellerCredential sc = obj as SellerCredential;

                cmd.CommandText = "update sellercredentials set password='******' where id=" + sc.Id;

                int result = cmd.ExecuteNonQuery();

                con.Close();

                return(result);
            }

            else
            {
                return(0);
            }
        }