public IHttpActionResult GetLogin(string name, string userid)
        {
            CHALOEntities db = new CHALOEntities();
            CH_USER objuser = new CH_USER();
            int pareseduser = Int32.Parse(userid);
            objuser = db.CH_USER.Where(s => s.USER_ID == pareseduser).FirstOrDefault<CH_USER>();

            objuser.USER_COUPONAPPLIED = true;

            objuser.USER_FIRSTNAME = name;
            db.Entry(objuser).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            List<CH_USER> list = db.Database.SqlQuery<CH_USER>("select * from ch_user where USER_ID="+ userid +" and user_status=1").ToList();

            // List<LOCATION> users = new List<LOCATION>();

            //return CreatedAtRoute("DefaultApi", new { id = users[0].USER_ID }, users);
            //CH_USER cH_USER = db.CH_USER.Find(userid);
            //if (cH_USER == null)
            //{
            //    return NotFound();
            //}

            return Ok(list);
        }
        public IHttpActionResult PutCH_USER(int id, CH_USER cH_USER)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != cH_USER.USER_ID)
            {
                return BadRequest();
            }

            db.Entry(cH_USER).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CH_USERExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult PostCH_USER(CH_USER cH_USER)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.CH_USER.Add(cH_USER);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = cH_USER.USER_ID }, cH_USER);
        }
        //    public IHttpActionResult checkcoupon(string userid)
        //    {
        //        CHALOEntities db = new CHALOEntities();
        //        CH_USER objuser = new CH_USER();
        //        List<USERCOUPON> list = db.Database.SqlQuery<USERCOUPON>("select * from usercoupons where coupon_userid='" + userid + "' ").ToList();
        //        return Ok(list);
        //    }
        public IHttpActionResult GetLogin(string userid)
        {
            CHALOEntities db = new CHALOEntities();
            CH_USER objuser = new CH_USER();

            List<USERCOUPON> list = db.Database.SqlQuery<USERCOUPON>("select * from usercoupons where coupon_userid=" + userid + " and coupon_status=1").ToList();

            // List<LOCATION> users = new List<LOCATION>();

            //return CreatedAtRoute("DefaultApi", new { id = users[0].USER_ID }, users);
            //CH_USER cH_USER = db.CH_USER.Find(userid);
            //if (cH_USER == null)
            //{
            //    return NotFound();
            //}

            return Ok(list);
        }
        public IHttpActionResult Gethistory(string email,string mobile)
        {
            CHALOEntities db = new CHALOEntities();
            List<CH_USER> list = new List<CH_USER>();
            if (email!="")
            {
                list = db.Database.SqlQuery<CH_USER>("select * from ch_user where user_emailid='" + email + "' or user_mobile='" + mobile + "'").ToList();
            }
            else if(mobile!="")
            {
                list = db.Database.SqlQuery<CH_USER>("select * from ch_user where user_mobile='" + mobile + "'").ToList();
            }
            if (list.Count>0)
            {
                CH_USER objuser = new CH_USER();
                int pareseduser = (list[0].USER_ID);
                objuser = db.CH_USER.Where(s => s.USER_ID == pareseduser).FirstOrDefault<CH_USER>();
                objuser.USER_COUPONAPPLIED = true;
                string pasword = common.CreatePassword(5);
                objuser.USER_PASSWORD = encryptdecrypt.Encrypt(pasword);
                db.Entry(objuser).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                bool status=common.sendmessage("As per your request, Your CHALO password has been changed. "+ pasword +" is your new password,Happily CHALO. ",""+ list[0].USER_MOBILE +"");
                StreamReader reader = new StreamReader(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/Emails/forgotemail.html")));
                string readFile = reader.ReadToEnd();
                string myString = "";
                myString = readFile;
                myString = myString.Replace("$$EMAIL$$", list[0].USER_EMAILID);
                myString = myString.Replace("$$PASSWORD$$", pasword);
                bool statusemail = common.sendemail(myString,"Your CHALO password has been reset","*****@*****.**",list[0].USER_EMAILID);

            }
            else
            {

            }
            return Ok(list);
        }
        public IHttpActionResult GetLogin(string Firstname, string Email, string Pass, string Mobile, string code,string regtype,string socialid)
        {
            common objcommon = new common();
            CH_USER user = new CH_USER();

            user.USER_FIRSTNAME = Firstname.Trim();
            //user.USER_LASTNAME = Lastname;
            user.USER_EMAILID = Email.Trim();
            user.USER_MOBILE = Mobile.Trim();
            user.USER_PASSWORD = encryptdecrypt.Encrypt(Pass.Trim());
            user.USER_STATUS = 1;
            if(regtype=="" || regtype==null)
            {
            user.USER_REGISTERTYPE = 1;
            }
            else
            {
                user.USER_REGISTERTYPE = Convert.ToInt32(regtype);
                user.USER_REGID = socialid;
            }
            user.USER_MODIFIEDBY = 1;
            user.USER_MODIFIEDDATE =common.getdate();
            user.USER_CREATEDBY = 1;
            user.USER_CREATEDATE = common.getdate();
            user.USER_USERNAME = Email.Trim();

            List<CH_USER> listusers = db.Database.SqlQuery<CH_USER>("select * from ch_user where user_username='******' or USER_MOBILE='" + Mobile.Trim() + "'").ToList();

            if (listusers.Count > 0)
            {
                return Json(new { id = "userexist" });
            }
            else
            {

                if (code != null && code != "")
                {

                    List<USERCOUPON> listcoupons = db.Database.SqlQuery<USERCOUPON>("select * from ch_user where coupon_name='" + code.Trim() + "'").ToList();

                    if (listcoupons.Count > 0)
                    {
                        user.USER_REFEREDBY = Convert.ToInt32(listcoupons[0].COUPON_USERID);
                        if (!ModelState.IsValid)
                        {
                            return BadRequest(ModelState);
                        }

                       CH_USER objuser=db.CH_USER.Add(user);
                        db.SaveChanges();

                        USERCOUPON objusercoupon=common.addusercoupon(objuser.USER_ID);

                        //firsttimeuser
                        bool status = common.FIRSTUSER100RS(objuser.USER_ID.ToString(), code, Convert.ToString(listcoupons[0].COUPON_USERID),listcoupons[0].COUPON_ID);

                        List<CH_USER> result = db.Database.SqlQuery<CH_USER>("select * from ch_user where USER_ID=" + objuser.USER_ID + "").ToList();
                        bool statusnew = common.sendmessage("Welcome to Chalo.Thanks for installing our app!We are delighted with your presence, Have a great ride. Refer your friend with the code " + objusercoupon.COUPON_NAME + " and get 100 RS in your CHALO wallet. For any assistance call us at 9900036467 or email at [email protected]", "" + objuser.USER_MOBILE + "");
                        StreamReader reader = new StreamReader(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/Emails/registeremail.html")));
                        string readFile = reader.ReadToEnd();
                        string myString = "";
                        myString = readFile;
                        myString = myString.Replace("$$NAME$$", objuser.USER_FIRSTNAME);
                        myString = myString.Replace("$$CODE$$", objusercoupon.COUPON_NAME);
                        bool statusemail = common.sendemail(myString, "Welcome to CHALO", "*****@*****.**", objuser.USER_EMAILID);

                        return Ok(result);
                    }
                    else
                    {
                        return Json(new { id = "coupondoesnotexist" });
                    }

                }
                else
                {

                    db.CH_USER.Add(user);
                    CH_USER objuser = db.CH_USER.Add(user);
                    db.SaveChanges();
                    USERCOUPON objusercoupon = common.addusercoupon(objuser.USER_ID);
                    bool status = common.FIRSTUSER100RS(objuser.USER_ID.ToString(), "","",0);

                    List<CH_USER> result = db.Database.SqlQuery<CH_USER>("select * from ch_user where USER_ID="+ objuser.USER_ID +"").ToList();
                     bool statusnew = common.sendmessage("Welcome to Chalo.Thanks for installing our app!We are delighted with your presence, Have a great ride. Refer your friend with the code "+ objusercoupon.COUPON_NAME + " and get 100 RS in your CHALO wallet. For any assistance call us at 9900036467 or email at [email protected]", "" + objuser.USER_MOBILE + "");
                    StreamReader reader = new StreamReader(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/Emails/registeremail.html")));
                    string readFile = reader.ReadToEnd();
                    string myString = "";
                    myString = readFile;
                    myString = myString.Replace("$$NAME$$", objuser.USER_FIRSTNAME);
                    myString = myString.Replace("$$CODE$$", objusercoupon.COUPON_NAME);
                    bool statusemail = common.sendemail(myString, "Welcome to CHALO", "*****@*****.**", objuser.USER_EMAILID);

                    return Ok(result);
                }

            }
        }
Ejemplo n.º 7
0
        internal static bool FIRSTUSER100RS(string USERID,string COUPONID,string couponuserid,int refcouponid)
        {
            int COUPONUSERID =1 ;
             if(COUPONID==null || COUPONID=="")
            {
                 COUPONUSERID= 1;
               }
             else
             {
                 COUPONUSERID = Convert.ToInt32(couponuserid);
             }

            CHALOEntities db=new CHALOEntities();
            //coupon applied status
            CH_USER objuser=new CH_USER();
            int pareseduser=Int32.Parse(USERID);
            objuser = db.Database.SqlQuery<CH_USER>("select top 1 * from ch_user where user_id='" + pareseduser + "' and user_status=1").FirstOrDefault<CH_USER>();

            objuser.USER_COUPONAPPLIED=true;

                objuser.USER_REFEREDBY=COUPONUSERID;
               db.Entry(objuser).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            //CREATING WALLET FOR USER
            WALLET OBJWALLET=new WALLET();
            OBJWALLET.WALLET_CREATEDBY=1;
            OBJWALLET.WALLET_CREATEDDATE=getdate();
            OBJWALLET.WALLET_MODIFIEDBY=1;
            OBJWALLET.WALLET_MODIFIEDDATE=getdate();
            OBJWALLET.WALLET_STATUS=1;
            OBJWALLET.WALLET_USERID=Int32.Parse(USERID);
            OBJWALLET.WALLET_AVAILABLEMONEY=decimal.Parse("0.00");

            OBJWALLET =db.WALLETs.Add(OBJWALLET);
            db.SaveChanges();

            //appliedcouponstableinsert

            APPLIEDCOUPON objcoupon=new APPLIEDCOUPON();

            objcoupon.APPLIED_REFERRALBONUS = false;
            if(COUPONID==null || COUPONID=="")
            {
                objcoupon.APPLIED_COUPONID = 101;
            objcoupon.APPLIED_COUPONNAME="CHALO-100";
                objcoupon.APPLIED_ADMINCOUPON=true;
                objcoupon.APPLIED_USERCOUPON=false;
                }
            else
            {
                objcoupon.APPLIED_COUPONID = refcouponid;

            objcoupon.APPLIED_COUPONNAME=COUPONID;
                  objcoupon.APPLIED_ADMINCOUPON=false;
                objcoupon.APPLIED_USERCOUPON=true;
              }
            objcoupon.APPLIED_CREATEDDATE=getdate();
                objcoupon.APPLIED_CREATEDBY=1;
            objcoupon.APPLIED_MODIFIEDBY=1;
            objcoupon.APPLIED_MODIFIEDDATE=getdate();
            objcoupon.APPLIED_ONETIME=true;
            objcoupon.APPLIED_STATUS=1;

                 objcoupon.APPLIED_USERID= COUPONUSERID;

               objcoupon=db.APPLIEDCOUPONS.Add(objcoupon);
            db.SaveChanges();

               // //l00rswalletdeposittransaction
               // transaction OBJTRANS=new transaction();
               // OBJTRANS.TRANS_AMOUNT=decimal.Parse("100.00");
               // OBJTRANS.TRANS_CREATEDBY=1;
               // OBJTRANS.TRANS_CRETEATEDDATE=getdate();
               // OBJTRANS.TRANS_MODE=1;
               // OBJTRANS.TRANS_MODENAME="wallet";
               // OBJTRANS.TRANS_MODIFIEDBY=1;
               // OBJTRANS.TRANS_MODIFIEDDATE=getdate();
               // OBJTRANS.TRANS_NAME="CHALO WALLET FIRST TIME USER 100RS";
               //OBJTRANS.TRANS_STATUS=1;
               //OBJTRANS.TRANS_USERID = Convert.ToInt32(USERID);
               //OBJTRANS.TRANS_CREDIT = true;
               //OBJTRANS.TRANS_DEBIT = false;

               // OBJTRANS=ADDTRANS(OBJTRANS);
               // db.SaveChanges();

            //
            //ADDING WALLET TRANS

               // WALLETTRANSACTION OBJWALLETTRANS=new WALLETTRANSACTION();
               // OBJWALLETTRANS.TRANS_COMMENT="CHALOWALLET FIRSTTIME USER 100";
               // OBJWALLETTRANS.TRANS_COUPONAPPLIEDID=objcoupon.APPLIED_ID;
               // OBJWALLETTRANS.TRANS_CREATEDBY=1;
               // OBJWALLETTRANS.TRANS_CREATEDDATE=getdate();
               // OBJWALLETTRANS.TRANS_ID=OBJTRANS.TRANS_ID;
               // OBJWALLETTRANS.TRANS_MODIFIEDBY=1;
               // OBJWALLETTRANS.TRANS_MODIFIEDDATE=getdate();
               // OBJWALLETTRANS.TRANS_STATUS=1;
               //OBJWALLETTRANS.TRANS_TRANSACTIONID=OBJTRANS.TRANS_ID;
               // OBJWALLETTRANS.TRANS_WALLETID=OBJWALLET.WALLET_ID;
               // OBJWALLETTRANS.TRANS_WALLETSTATUS=1;
               // OBJWALLETTRANS.TRANS_WALLETTYPE=1;
               //OBJWALLETTRANS=db.WALLETTRANSACTIONS.Add(OBJWALLETTRANS);
               //  db.SaveChanges();

            //adding 100 to wallet
            // OBJWALLET = db.WALLETs.Where(s => s.WALLET_ID == OBJWALLET.WALLET_ID).FirstOrDefault<WALLET>();
            //OBJWALLET.WALLET_AVAILABLEMONEY=decimal.Parse("100.00");
            // db.Entry(OBJWALLET).State = System.Data.Entity.EntityState.Modified;
            // db.SaveChanges();

            //addingwallettoreferredperson
            if(couponuserid!=null && couponuserid!="")
            {
                int cid = Int32.Parse(couponuserid);
                //appliedcouponstableinsert

                APPLIEDCOUPON objcouponref = new APPLIEDCOUPON();
                objcouponref.APPLIED_COUPONID = 101;

                objcouponref.APPLIED_COUPONNAME = objcoupon.APPLIED_COUPONNAME;
                objcouponref.APPLIED_REFERRALBONUS = true;
                objcouponref.APPLIED_COUPONNAME = COUPONID;
                objcouponref.APPLIED_ADMINCOUPON = false;
                objcouponref.APPLIED_USERCOUPON = true;

                objcouponref.APPLIED_CREATEDDATE = getdate();
                objcouponref.APPLIED_CREATEDBY = 1;
                objcouponref.APPLIED_MODIFIEDBY = 1;
                objcouponref.APPLIED_MODIFIEDDATE = getdate();
                objcouponref.APPLIED_ONETIME = true;
                objcouponref.APPLIED_STATUS = 1;

                objcouponref.APPLIED_USERID = COUPONUSERID;

                objcouponref = db.APPLIEDCOUPONS.Add(objcouponref);
                db.SaveChanges();

                //l00rswalletdeposittransaction
                transaction OBJTRANSref = new transaction();
                OBJTRANSref.TRANS_AMOUNT = decimal.Parse("100.00");
                OBJTRANSref.TRANS_CREATEDBY = 1;
                OBJTRANSref.TRANS_CRETEATEDDATE = getdate();
                OBJTRANSref.TRANS_MODE = 1;
                OBJTRANSref.TRANS_MODENAME = "wallet";
                OBJTRANSref.TRANS_MODIFIEDBY = 1;
                OBJTRANSref.TRANS_MODIFIEDDATE = getdate();
                OBJTRANSref.TRANS_NAME = "CHALO WALLET refered USER ";
                OBJTRANSref.TRANS_STATUS = 1;
                OBJTRANSref.TRANS_USERID = Convert.ToInt32(couponuserid);
                OBJTRANSref.TRANS_CREDIT = true;
                OBJTRANSref.TRANS_DEBIT = false;
                OBJTRANSref = ADDTRANS(OBJTRANSref);
                db.SaveChanges();

                //ADDING WALLET TRANS

               WALLET objwalletref=db.WALLETs.Where(s => s.WALLET_USERID == cid).FirstOrDefault<WALLET>();

                WALLETTRANSACTION OBJWALLETTRANSref = new WALLETTRANSACTION();
                OBJWALLETTRANSref.TRANS_COMMENT = "CHALOWALLET FIRSTTIME USER 100";
                OBJWALLETTRANSref.TRANS_COUPONAPPLIEDID = objcouponref.APPLIED_ID;
                OBJWALLETTRANSref.TRANS_CREATEDBY = 1;
                OBJWALLETTRANSref.TRANS_CREATEDDATE = getdate();
                OBJWALLETTRANSref.TRANS_ID = OBJTRANSref.TRANS_ID;
                OBJWALLETTRANSref.TRANS_MODIFIEDBY = 1;
                OBJWALLETTRANSref.TRANS_MODIFIEDDATE = getdate();
                OBJWALLETTRANSref.TRANS_STATUS = 1;
                OBJWALLETTRANSref.TRANS_TRANSACTIONID = OBJTRANSref.TRANS_ID;
                OBJWALLETTRANSref.TRANS_WALLETID = objwalletref.WALLET_ID;
                OBJWALLETTRANSref.TRANS_WALLETSTATUS = 1;
                OBJWALLETTRANSref.TRANS_WALLETTYPE = 1;
                OBJWALLETTRANSref = db.WALLETTRANSACTIONS.Add(OBJWALLETTRANSref);
                db.SaveChanges();

            WALLET OBJWALLETREFERRED = db.Database.SqlQuery<WALLET>("select * from wallet where wallet_userid=" + cid + "").FirstOrDefault<WALLET>();
            OBJWALLETREFERRED.WALLET_AVAILABLEMONEY = OBJWALLETREFERRED.WALLET_AVAILABLEMONEY+decimal.Parse("100.00");
            db.Entry(OBJWALLETREFERRED).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            }

             return true;
        }