public ActionResult doLogin(UserLoginVM rec)
        {
            if (ModelState.IsValid)
            {
                UserTbl urec = entity.UserTbls.SingleOrDefault(p => p.EmailID == rec.EmailID && p.Password == rec.Password);
                if (urec != null)
                {
                    Session["UserID"]   = urec.UserID;
                    Session["UserName"] = urec.UserName;
                    if (Session["ProdID"] != null)
                    {
                        Int64 prod = Convert.ToInt64(Session["ProdID"]);
                        Session.Remove("ProdID");
                        return(RedirectToAction("AddToCart", "Cart", new { id = prod }));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                ModelState.AddModelError("", "Invalid Email ID or Password!");
                return(View(rec));
            }
            return(View(rec));
        }
        public IHttpActionResult PutUserTbl(int id, UserTbl userTbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userTbl.UserId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public HttpResponseMessage AddUserRoleTbl(UserDataModel userDataModal)
        {
            try
            {
                UserTbl userTbl = new UserTbl();
                userTbl.UserName  = userDataModal.UserName;
                userTbl.UserPwd   = userDataModal.UserPwd;
                userTbl.LastName  = userDataModal.LastName;
                userTbl.FirstName = userDataModal.FirstName;
                userTbl.UserEmail = userDataModal.UserEmail;
                userTbl.UserPhone = userDataModal.UserPhone;

                int[] roleId = userDataModal.RoleId;
                db.UserTbls.Add(userTbl);
                db.SaveChanges();

                int latestUserId = userTbl.UserId;

                foreach (int items in roleId)
                {
                    UserRoleTbl userRoleTbl = new UserRoleTbl();
                    userRoleTbl.UserId = latestUserId;
                    userRoleTbl.RoleId = items;
                    db.UserRoleTbls.Add(userRoleTbl);
                }
                db.SaveChanges();
                var message = Request.CreateResponse(HttpStatusCode.Created, userTbl);
                return(message);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,FirstName,LastName")] UserTbl userTbl)
        {
            if (id != userTbl.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userTbl);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserTblExists(userTbl.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userTbl));
        }
Beispiel #5
0
 public HttpResponseMessage Login(UserTbl model)
 {
     if (ModelState.IsValid)
     {
         var encryptedPasswordString = EncryptDecryptPassword.EncryptPlainTextToCipherText(model.Password);
         var user = db.UserTbls.FirstOrDefault(item => item.UserName == model.UserName && item.Password == encryptedPasswordString);
         if (user != null)
         {
             user.Token = Guid.NewGuid();
             db.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, new
             {
                 Token = user.Token,
                 Name = string.Concat(user.FirstName, " ", user.LastName)
             }));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Username and password"));
         }
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
Beispiel #6
0
        ActionOutput <UserModel> IUserManager.RegisterUser(UserModel model)
        {
            ActionOutput <UserModel> res = new ActionOutput <UserModel>();

            try
            {
                var Phone_Exists = Context.UserTbls.Where(p => p.Phone == model.Phone && p.Status != (int)UserStatuss.Deleted).Any();
                if (!Phone_Exists)
                {
                    UserTbl _user = new UserTbl();
                    _user.FirstName = model.FirstName;
                    _user.LastName  = model.LastName;
                    _user.Phone     = model.Phone;
                    _user.Email     = model.Email;
                    _user.Password  = UtilitiesHelp.EncryptPassword(model.Password, true);
                    _user.RoleId    = model.RoleId;
                    _user.Address   = model.Address;
                    _user.City      = model.City;
                    _user.Latitute  = model.Latitute;
                    _user.Longitute = model.Longitute;
                    _user.Province  = model.Province;
                    _user.OTP       = UtilitiesHelp.GenerateOTP();
                    _user.Status    = (int)UserStatuss.Registered;
                    _user.CreatedOn = DateTime.Now;
                    Context.UserTbls.Add(_user);
                    Context.SaveChanges();

                    //DEV
                    const string accountSid = "AC3d3a026d31db3d33865fbf53259a0000";
                    const string authToken  = "685ce72fc4d6b7c61d9804802de34c81";
                    //LIVE
                    //const string accountSid = "ACa8fc7a52b4ee46f45cfc07c1cccf5137";
                    //const string authToken = "3c83a5093211b78584f34265691163dd";

                    TwilioClient.Init(accountSid, authToken);

                    var message = MessageResource.Create(
                        body: "OTP for ApniMaa app is ." + _user.OTP,
                        from: new Twilio.Types.PhoneNumber("+12063374541"),
                        to: new Twilio.Types.PhoneNumber("+91" + _user.Phone)
                        );
                    res.Object  = new UserModel(_user);
                    res.Status  = ActionStatus.Successfull;
                    res.Message = "User Registered successfully";
                }
                else
                {
                    res.Status  = ActionStatus.Error;
                    res.Message = "Phone Number already registered.";
                }
            }
            catch (Exception ex)
            {
                res.Status  = ActionStatus.Error;
                res.Message = "Some Errpr Occurred";
            }

            return(res);
        }
Beispiel #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            UserTbl userTbl = db.UserTbls.Find(id);

            db.UserTbls.Remove(userTbl);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,username_,password,admin")] UserTbl userTbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userTbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userTbl));
 }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "UserId,Usuario,Nombre,Apellido,Clave")] UserTbl userTbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userTbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userTbl));
 }
        public ActionResult Create([Bind(Include = "Id,username_,password,admin")] UserTbl userTbl)
        {
            if (ModelState.IsValid)
            {
                db.UserTbls.Add(userTbl);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userTbl));
        }
 public ActionResult Edit([Bind(Include = "user_id,user_name,user_mail,user_Pass,Dep_id")] UserTbl userTbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userTbl).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Dep_id = new SelectList(db.departmenttbls, "dep_id", "dep_name", userTbl.Dep_id);
     return(View(userTbl));
 }
        public ActionResult Register(UserTbl rec)
        {
            if (ModelState.IsValid)
            {
                entity.UserTbls.Add(rec);
                entity.SaveChanges();
                return(RedirectToAction("doLogin"));
            }

            return(View(rec));
        }
Beispiel #13
0
        public async Task <IActionResult> Create([Bind("UserId,FirstName,LastName")] UserTbl userTbl)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userTbl);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userTbl));
        }
Beispiel #14
0
        public ActionResult Create([Bind(Include = "UserId,Usuario,Nombre,Apellido,Clave")] UserTbl userTbl)
        {
            if (ModelState.IsValid)
            {
                db.UserTbls.Add(userTbl);
                db.SaveChanges();
                //return RedirectToAction("Index");
                return(View());
            }

            return(View(userTbl));
        }
        public ActionResult Create([Bind(Include = "user_id,user_name,user_mail,user_Pass,Dep_id")] UserTbl userTbl)
        {
            if (ModelState.IsValid)
            {
                db.UserTbls.Add(userTbl);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Dep_id = new SelectList(db.departmenttbls, "dep_id", "dep_name", userTbl.Dep_id);
            return(View(userTbl));
        }
        public IHttpActionResult PostUserTbl(UserTbl userTbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.UserTbls.Add(userTbl);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = userTbl.UserId }, userTbl));
        }
Beispiel #17
0
        public IHttpActionResult ValidateUser(string userName)
        {
            UserTbl userTbl = db.UserTbls.Where(x => x.UserName == userName).FirstOrDefault();

            if (userTbl.DeletedDate == null)
            {
                return(Ok(userTbl.UserId));
            }
            else
            {
                return(Ok(-1));
            }
        }
        public IHttpActionResult DeleteUserTbl(int id)
        {
            UserTbl userTbl = db.UserTbls.Find(id);

            if (userTbl == null)
            {
                return(NotFound());
            }

            db.UserTbls.Remove(userTbl);
            db.SaveChanges();

            return(Ok(userTbl));
        }
Beispiel #19
0
        // GET: UserTbls/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserTbl userTbl = db.UserTbls.Find(id);

            if (userTbl == null)
            {
                return(HttpNotFound());
            }
            return(View(userTbl));
        }
Beispiel #20
0
        public JsonResult DeleteCoach(int _CoachID)
        {
            UserTbl user   = db.UserTbls.SingleOrDefault(x => x.ID == _CoachID);
            bool    result = false;

            if (user != null)
            {
                db.UserTbls.Remove(user);
                db.SaveChanges();
                result = true;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #21
0
        public HttpResponseMessage UpdateUser(int id, UserDataModel userDataModel)
        {
            try
            {
                UserTbl userTbl = new UserTbl();
                var     data    = db.UserTbls.FirstOrDefault(x => x.UserId == id);
                if (data == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                       "UserTbl with userid = " + id.ToString() + " not found to update"));
                }
                else
                {
                    data.LastName  = userDataModel.LastName;
                    data.FirstName = userDataModel.FirstName;
                    data.UserEmail = userDataModel.UserEmail;
                    data.UserPhone = userDataModel.UserPhone;
                    db.SaveChanges();

                    List <UserRoleTbl> myUserRoleTbl = db.UserRoleTbls.Where(x => x.UserId == id).ToList();

                    if (myUserRoleTbl.Count() > 0)
                    {
                        for (int j = 0; j < myUserRoleTbl.Count(); j++)
                        {
                            db.UserRoleTbls.Remove(myUserRoleTbl[j]);
                        }
                        db.SaveChanges();
                    }

                    int[] roleId = userDataModel.RoleId;
                    int   id1    = id;

                    foreach (int items in roleId)
                    {
                        UserRoleTbl userRoleTbl = new UserRoleTbl();
                        userRoleTbl.UserId = id1;
                        userRoleTbl.RoleId = items;
                        db.UserRoleTbls.Add(userRoleTbl);
                    }
                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Created, data));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Beispiel #22
0
        public ActionResult SelectCoach(int _id)
        {
            UserTbl     user     = db.UserTbls.SingleOrDefault(x => x.ID == _id);
            CoatchModel NewCoach = new CoatchModel
            {
                TrainingName = user.TrainingTbl.TrainingName,
                ID           = user.ID,
                CoachName    = user.CoachName,
                PhoneNumber  = user.PhoneNumber,
                Age          = user.Age,
                TrainingID   = user.TrainingID
            };

            return(View(NewCoach));
        }
Beispiel #23
0
        public static UserTbl CreateUserTbl(UserDTO u)
        {
            UserTbl u1 = new UserTbl()
            {
                id        = u.id,
                isManager = u.isManager,
                ravkav    = u.ravkav,
                password  = u.password,
                firstName = u.firstName,
                lastName  = u.lastName,
                profileId = u.profileId
            };

            return(u1);
        }
        // GET: AddUser/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserTbl userTbl = db.UserTbls.Find(id);

            if (userTbl == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Dep_id = new SelectList(db.departmenttbls, "dep_id", "dep_name", userTbl.Dep_id);
            return(View(userTbl));
        }
Beispiel #25
0
        public string UserLogin(UserTbl userLogin)
        {
            SessionResponse response = new SessionResponse();

            try
            {
                // UserTbl userLogin = JsonConvert.DeserializeObject<UserTbl>(userJson);
                var user = _userOperations.GetUser(userLogin.Username ?? userLogin.Email, userLogin.UserPassword);

                if (user == null)
                {
                    response.ResultFlag    = false;
                    response.ResultMessage = UserMessages.MissingUser;
                    response.ResultCode    = ResultCode.MissingUser.ToString();
                }
                else
                {
                    response.ResultFlag    = true;
                    response.ResultMessage = UserMessages.LoginSuccess;
                    response.ResultCode    = ResultCode.LoginSuccess.ToString();
                    response.UserDetails   = new UserModel()
                    {
                        Email    = user.Email,
                        Name     = user.Name,
                        Username = user.Username,
                        UserPreferredLanguage = user.UserPreferredLanguage,
                        UserTypeId            = user.UserTypeId,
                        UserId = user.UserID
                    };
                    if (response.UserDetails.UserTypeId == (int)UserTypesName.RestaurantAdministrator)
                    {
                        response.UserDetails.HasRestaurantConfigured = Convert.ToBoolean(_userOperations.CheckAdminHasRestaurant(response.UserDetails.Username, response.UserDetails.Email));
                    }
                    response.SessionKey = Guid.NewGuid().ToString();

                    HttpContext.Current.Session.Add("Session_ID", response.SessionKey);
                }
            }
            catch (Exception ex)
            {
                response.ResultFlag = false;
                response.ResultCode = ResultCode.OperationFailed.ToString();
                _logger.Log("UserLogin_Exception: ", ex.Message);
            }
            //return response;
            return(JsonConvert.SerializeObject(response));
        }
        public void makePayment(int tripId, int cost, int userId)
        {
            UserTbl     user    = DB.UserTbls.Find(userId);
            string      card    = user.cardNum;
            PaymentsTbl payment = new PaymentsTbl();

            payment.cardNum = card;
            payment.cost    = cost;
            payment.tripID  = tripId;
            DB.PaymentsTbls.Add(payment);
            TripTbl trip = DB.TripTbls.Find(tripId);

            trip.status = "finished_paid";
            BikeTbl bike = DB.BikeTbls.Find(trip.Bike);

            bike.status = "locked";
            DB.SaveChanges();
        }
Beispiel #27
0
        public static bool AddUser(UserDTO user)
        {
            UserTbl u = Extend.CreateUserTbl(user);

            try
            {
                using (RavKav r = new RavKav())
                {
                    r.UserTbls.Add(u);
                    r.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #28
0
 public UserModel(UserTbl obj)
 {
     this.UserID    = obj.Id;
     this.RoleId    = obj.RoleId;
     this.RoleName  = UtilitiesHelp.EnumToDecription(typeof(UserRoleTypes), obj.RoleId.Value);
     this.Email     = obj.Email;
     this.FirstName = obj.FirstName;
     this.LastName  = obj.LastName;
     this.Password  = UtilitiesHelp.EncryptPassword(obj.Password, true);
     this.Phone     = obj.Phone;
     this.City      = obj.City;
     this.Province  = obj.Province;
     this.Address   = obj.Address;
     this.Longitute = obj.Longitute;
     this.Latitute  = obj.Latitute;
     this.RoleId    = obj.RoleId;
     this.Status    = obj.Status;
 }
Beispiel #29
0
        public string Register(UserTbl userRegister)
        {
            ResponseDataModel response = new ResponseDataModel();

            try
            {
                response.ResultMessage = _userOperations.RegisterUser(userRegister);
                response.ResultFlag    = response.ResultMessage != UserMessages.DuplicateUser;
                response.ResultCode    = response.ResultMessage != UserMessages.DuplicateUser ? ResultCode.RegisterSuccess.ToString() : ResultCode.UserInvalid.ToString();
            }
            catch (Exception ex)
            {
                response.ResultFlag = false;
                response.ResultCode = ResultCode.OperationFailed.ToString();
                _logger.Log("RegisterUser_Exception: ", ex.Message);
            }

            return(JsonConvert.SerializeObject(response));
        }
        public void startTrip(int userId, int bikeID)
        {
            TripTbl newTrip = new TripTbl();
            UserTbl user    = DB.UserTbls.Find(userId);

            newTrip.startLongitude = user.longitude;
            newTrip.startLatitude  = user.latitude;
            newTrip.status         = "in-progress";
            newTrip.startTime      = DateTime.Now;
            BikeTbl bike = DB.BikeTbls.Find(bikeID);

            if (bike.status.Equals("unlocked"))
            {
                newTrip.BikeTbl = bike;
                newTrip.Bike    = bikeID;
                newTrip.UserID  = userId;
                DB.TripTbls.Add(newTrip);
                bike.status = "occupied";
                DB.SaveChanges();
            }
        }