public ActionResult EditRoles(FormCollection request)
        {
            int id = int.Parse(request.Get("id"));


            var oldRoles = db.sec_users_roles.Where(a => a.user_id == id);

            foreach (var role in oldRoles)
            {
                db.Entry(role).State = EntityState.Deleted;
            }
            db.SaveChanges();
            foreach (var roleid in request.Get("roles[]").Split(','))
            {
                int role_id = int.Parse(roleid.ToString());
                db.sec_users_roles.Add(new sec_users_roles()
                {
                    role_id = role_id, user_id = id
                });
            }

            db.SaveChanges();
            if (Request.IsAjaxRequest())
            {
                return(Json(new { type = "success", mesaage = "Save success" }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Create(tbl_genders type)
        {
            var tbl_genders = new tbl_genders();

            var dic = new Dictionary <string, string>();

            foreach (string lang in BLL.GlobalData.Languages)
            {
                dic.Add(lang, Request.Form["name[" + lang + "]"]);
            }

            tbl_genders.name = JsonConvert.SerializeObject(dic);

            db.tbl_genders.Add(tbl_genders);
            db.SaveChanges();
            if (Request.IsAjaxRequest())
            {
                var res = new { type = "success", message = "Save Success" };
                return(Json(res));
            }
            return(RedirectToAction("Index"));

            //if (Request.IsAjaxRequest())
            //{
            //    var res = new { type = "error", message = "Error while save !" };
            //    return Json(res);
            //}

            //return View(tbl_genders);
        }
Example #3
0
        public ActionResult Create([Bind(Include = "id,name,role_key,description")] sec_roles sec_roles)
        {
            if (ModelState.IsValid)
            {
                db.sec_roles.Add(sec_roles);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sec_roles));
        }
        public ActionResult Create([Bind(Include = "id,setting_key,setting_name,setting_value,setting_type,datasource_url,datasource_json,setting_group,display,sequance")] tbl_setting tbl_setting)
        {
            if (ModelState.IsValid)
            {
                db.tbl_setting.Add(tbl_setting);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tbl_setting));
        }
Example #5
0
        public ActionResult Create([Bind(Include = "id,pwd,reset_pwd_token,facebook_token,twitter_token,google_token,instagram_token,confirm_mail_token,mail_verified,phone_verified,firebase_uid")] sec_users sec_users)
        {
            if (ModelState.IsValid)
            {
                db.sec_users.Add(sec_users);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.id = new SelectList(db.tbl_accounts, "id", "first_name", sec_users.id);
            return(View(sec_users));
        }
Example #6
0
        public ActionResult Create([Bind(Include = "id,role_id,model_name,method_name,force_filter")] sec_access_right sec_access_right)
        {
            if (ModelState.IsValid)
            {
                db.sec_access_right.Add(sec_access_right);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.role_id = new SelectList(db.sec_roles, "id", "name", sec_access_right.role_id);
            return(View(sec_access_right));
        }
Example #7
0
        public ActionResult Create([Bind(Include = "id,user_id,start_time,end_time,ip,agent,browser,country,city,country_code,isp,lat,lon,timezone,paltform,device_id")] sec_sessions sec_sessions)
        {
            if (ModelState.IsValid)
            {
                sec_sessions.id = Guid.NewGuid();
                db.sec_sessions.Add(sec_sessions);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.user_id = new SelectList(db.sec_users, "id", "pwd", sec_sessions.user_id);
            return(View(sec_sessions));
        }
        public ActionResult Create([Bind(Include = "id,user_id,role_id")] sec_users_roles sec_users_roles)
        {
            if (ModelState.IsValid)
            {
                db.sec_users_roles.Add(sec_users_roles);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.role_id = new SelectList(db.sec_roles, "id", "name", sec_users_roles.role_id);
            ViewBag.user_id = new SelectList(db.sec_users, "id", "pwd", sec_users_roles.user_id);
            return(View(sec_users_roles));
        }
Example #9
0
        public static APIResult <LoginResponse> Register(tbl_accounts acc, string password, string FirebaseUID, NameValueCollection request)
        {
            using (var ctx = new MainEntities())
            {
                var dbuser = ctx.tbl_accounts.Include("sec_users").Where(a => a.sec_users.firebase_uid == FirebaseUID).FirstOrDefault();
                if (dbuser == null)
                {
                    dbuser = acc;

                    ctx.tbl_accounts.Add(dbuser);
                    try
                    {
                        ctx.SaveChanges();
                        sec_users sec_user = new sec_users();

                        sec_user.pwd            = password;
                        sec_user.id             = dbuser.id;
                        sec_user.mail_verified  = true;
                        sec_user.firebase_uid   = FirebaseUID;
                        sec_user.phone_verified = true;
                        ctx.sec_users.Add(sec_user);
                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        return(APIResult <LoginResponse> .Error(ResponseCode.BackendDatabase, ex.Message + "save changes1"));
                    }
                }
                else
                {
                    return(APIResult <LoginResponse> .Error(ResponseCode.BackendDatabase, "This user already exists !"));
                }

                var returned = new LoginResponse {
                    account = acc
                };

                var session = GetNewSession(dbuser.sec_users, request, 1);

                if (session.code != ResponseCode.Success)
                {
                    return(APIResult <LoginResponse> .Error(session.code, session.message));
                }

                returned.token = session.data.id;
                returned.roles = ctx.sec_users_roles.Include("sec_roles").Where(a => a.user_id == acc.id).Select(b => b.sec_roles.role_key).ToArray();

                return(APIResult <LoginResponse> .Success(returned, "Register sucessfuly !"));
            }
        }
        public ActionResult Create([Bind(Include = "id,first_name,last_name,date_of_birth,mobile,email,register_time,is_deleted,gender_id,id_no,driver_license_no,city_id,country_id")] tbl_accounts tbl_accounts)
        {
            if (ModelState.IsValid)
            {
                db.tbl_accounts.Add(tbl_accounts);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.id         = new SelectList(db.sec_users, "id", "pwd", tbl_accounts.id);
            ViewBag.city_id    = new SelectList(db.tbl_cities, "id", "name", tbl_accounts.city_id);
            ViewBag.country_id = new SelectList(db.tbl_countries, "id", "name", tbl_accounts.country_id);
            ViewBag.gender_id  = new SelectList(db.tbl_genders, "id", "name", tbl_accounts.gender_id);
            return(View(tbl_accounts));
        }
Example #11
0
        public static bool Logout()
        {
            sec_sessions session = User;

            if (session == null)
            {
                return(true);
            }

            session.end_time = DateTime.Now;
            using (var db = new MainEntities())
            {
                db.Entry(session).State = System.Data.Entity.EntityState.Modified;
                if (db.SaveChanges() == 0)
                {
                    return(false);
                }
            }

            HttpContext.Current.Response.Cookies.Clear();
            HttpContext.Current.Session.Clear();


            return(true);
        }
Example #12
0
        public APIResult <bool> Rate(int id, RateRequest request)
        {
            var u = APIRequest.User(HttpContext.Current.Request);

            using (var ctx = new MainEntities())
            {
                var books = ctx.trip_book.Include("trip_request_details").Include("trip_request_details.trip_request").Where(a => a.trip_share_details_id == id && a.trip_request_details.trip_request.created_by == u.Entity.id);
                if (books == null || books.Count() == 0)
                {
                    return(APIResult <bool> .Error(ResponseCode.UserValidationField, "This trip not found !"));
                }
                foreach (var book in books)
                {
                    //if (book.trip_request_details.trip_request.rider_id == u.Entity.id)
                    //{
                    //    return APIResult<bool>.Error(ResponseCode.UserValidationField, "You cannot rate this trip!");
                    //}

                    book.rider_rate     = request.rate;
                    book.rate_comment   = request.comment;
                    book.rate_reason_id = request.reason_id;

                    ctx.Entry(book).State = System.Data.Entity.EntityState.Modified;
                }



                ctx.SaveChanges();

                return(APIResult <bool> .Success(true));
            }
        }
Example #13
0
        public bool RequestResetPassword_byMail(string Email)
        {
            using (MainEntities ctx = new MainEntities())
            {
                var acc = ctx.tbl_accounts.Where(x => x.email == Email).FirstOrDefault();

                var user = ctx.sec_users.Find(acc.id);


                if (user != null)
                {
                    user.reset_pwd_token = Guid.NewGuid().ToString();

                    ctx.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();

                    StringBuilder mailBody = new StringBuilder();
                    var           setting  = Libs.Settings.AppSetting.Where(a => a.setting_key == "site_url").FirstOrDefault();
                    string        ResetURL = "";
                    if (setting != null)
                    {
                        ResetURL = setting.setting_value + "/forgot-password/";
                    }
                    else
                    {
                        ResetURL = HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
                    }


                    General.SendEmail(Email, "Metookey Reset Password", "Please reset your password by clicking <a href=\"" + ResetURL + user.reset_pwd_token + "\">here</a>");
                    return(true);
                }
            }
            return(false);
        }
Example #14
0
        public APIResult <DAL.tbl_vehicles> Put(int id, DAL.tbl_vehicles value)
        {
            try
            {
                using (var ctx = new MainEntities())
                {
                    var u = APIRequest.User(HttpContext.Current.Request);

                    var v = ctx.tbl_vehicles.Find(id);

                    //v.id = id;
                    v.capacity   = value.capacity;
                    v.color      = value.color;
                    v.model      = value.model;
                    v.license_no = value.license_no;


                    //ctx.Set<DAL.tbl_vehicles>().Attach(v);
                    ctx.Entry(v).State = System.Data.Entity.EntityState.Modified;
                    var result = ctx.SaveChanges();
                    if (result <= 0)
                    {
                        return(APIResult <DAL.tbl_vehicles> .Error(ResponseCode.BackendDatabase, "Error while saving data!"));
                    }
                    return(APIResult <DAL.tbl_vehicles> .Success(value, "API_SUCCESS"));
                }
            }
            catch (Exception ex)
            {
                return(APIResult <DAL.tbl_vehicles> .Error(ResponseCode.BackendDatabase, ex.Message));
            }
        }
Example #15
0
        public void EditUserDetails(UserDetails insert)
        {
            using (var dbContext = new MainEntities())
            {
                var dtls = dbContext.UserDetails.Where(x => x.UserId == insert.UserId).FirstOrDefault();
                //var newcardetail = dbContext.CarDetails.Where(x => x.Id == insert.UserId);

                dtls.UserId        = insert.UserId;
                dtls.FullName      = insert.FullName;
                dtls.UserEmail     = insert.UserEmail;
                dtls.Address       = insert.Address;
                dtls.PasswordHash  = insert.PasswordHash;
                dtls.CivilIdNumber = insert.CivilIdNumber;



                var cars = dbContext.CarDetails.Where(x => x.UserId == insert.UserId).SingleOrDefault();
                cars.CarLicense             = insert.CarLicense;
                dbContext.Entry(dtls).State = EntityState.Modified;
                //if (cars.Count() > 0)
                //{
                dbContext.Entry(cars).State = EntityState.Modified;
                //}


                dbContext.SaveChanges();
            }
        }
Example #16
0
        public APIResult <bool> EditMyProfile(tbl_accounts request)
        {
            using (var ctx = new MainEntities())
            {
                var u   = APIRequest.User(HttpContext.Current.Request);
                var acc = ctx.tbl_accounts.Find(u.Entity.id);
                if (acc == null)
                {
                    return(APIResult <bool> .Error(ResponseCode.DevNotFound, "This account not found!", false));
                }

                acc.first_name        = request.first_name;
                acc.last_name         = request.last_name;
                acc.gender_id         = request.gender_id;
                acc.city_id           = request.city_id;
                acc.driver_license_no = request.driver_license_no;
                acc.id_no             = request.id_no;
                acc.date_of_birth     = request.date_of_birth;
                acc.country_id        = request.country_id;

                ctx.Entry(acc).State = System.Data.Entity.EntityState.Modified;

                try
                {
                    ctx.SaveChanges();
                    return(APIResult <bool> .Success(true));
                }
                catch (Exception ex)
                {
                    return(APIResult <bool> .Error(ResponseCode.BackendDatabase, ex.Message, false));
                }
            }
        }
Example #17
0
        public ActionResult DeleteConfirmed(int id)
        {
            trip_request_details trip_request_details = db.trip_request_details.Find(id);

            db.trip_request_details.Remove(trip_request_details);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #18
0
        public ActionResult DeleteConfirmed(int id)
        {
            trip_share trip_share = db.trip_share.Find(id);

            db.trip_share.Remove(trip_share);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #19
0
        public ActionResult DeleteConfirmed(int id)
        {
            rptBooking rptBooking = db.rptBooking.Find(id);

            db.rptBooking.Remove(rptBooking);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #20
0
        public static APIResult <sec_sessions> GetNewSession(sec_users usr, NameValueCollection request, int platform = 1)
        {
            using (var ctx = new MainEntities())
            {
                IPResult s = new IPResult();

                string   ip    = "";
                string   agent = "";
                IPResult iploc = new IPResult();

                try
                {
                    ip    = request.Get("REMOTE_ADDR");
                    agent = request.Get("HTTP_USER_AGENT");

                    iploc = General.GetResponse("http://ip-api.com/json/" + ip);
                }
                catch (Exception ex)
                {
                    // return APIResult<sec_sessions>.Error(ResponseCode.BackendServerRequest, ex.Message + "get location ip:" + ip + " agent:" + agent);
                }
                try
                {
                    var userSessions = ctx.sec_sessions.Where(a => a.user_id == usr.id && a.end_time == null && a.paltform == platform).FirstOrDefault();
                    if (userSessions != null)
                    {
                        return(APIResult <sec_sessions> .Success(userSessions, "User already logon!"));
                    }

                    Sessions ses = new Sessions();
                    ses.Entity.user_id = usr.id;
                    ses.Entity.ip      = request.Get("REMOTE_ADDR");
                    //IPResult iploc = new IPResult();// General.GetResponse("http://ip-api.com/json/" + ses.Entity.ip);

                    ses.Entity.isp          = iploc.isp;
                    ses.Entity.lat          = iploc.lat;
                    ses.Entity.lon          = iploc.lon;
                    ses.Entity.timezone     = iploc.timezone;
                    ses.Entity.city         = iploc.city;
                    ses.Entity.country      = iploc.country;
                    ses.Entity.country_code = iploc.countryCode;
                    ses.Entity.agent        = request.Get("HTTP_USER_AGENT");
                    ses.Entity.paltform     = platform;
                    ses.Entity.browser      = General.getAgent(ses.Entity.agent).name;
                    ctx.sec_sessions.Add(ses.Entity);

                    ctx.SaveChanges();

                    return(APIResult <sec_sessions> .Success(ses.Entity, "success"));
                }
                catch (Exception ex)
                {
                    return(APIResult <sec_sessions> .Error(ResponseCode.BackendDatabase, ex.Message));
                }
            }
        }
Example #21
0
        public ActionResult DeleteConfirmed(int id)
        {
            trip_request trip_request = db.trip_request.Find(id);

            db.trip_request.Remove(trip_request);
            db.SaveChanges();
            if (Request.IsAjaxRequest())
            {
                return(Json(new { type = "success", message = "Deleted Success" }));
            }
            return(RedirectToAction("Index"));
        }
Example #22
0
        public APIResult <DAL.tbl_vehicles> Post(DAL.tbl_vehicles value)
        {
            try
            {
                var u = APIRequest.User(HttpContext.Current.Request);

                value.owner_id   = u.Entity.id;
                value.created_at = DateTime.Now;
                value.created_by = u.Entity.id;

                using (var ctx = new MainEntities())
                {
                    ctx.Set <DAL.tbl_vehicles>().Add(value);
                    ctx.Entry(value).State = System.Data.Entity.EntityState.Added;

                    if (ctx.SaveChanges() <= 0)
                    {
                        if (u.hasRole("driver"))
                        {
                            ctx.tbl_drivers_vehicles_rel.Add(new tbl_drivers_vehicles_rel()
                            {
                                vehicle_id = value.id,
                                created_at = DateTime.Now,
                                created_by = u.Entity.id,
                                driver_id  = u.Entity.id,
                                status     = 1
                            });

                            ctx.SaveChanges();
                        }
                        return(APIResult <DAL.tbl_vehicles> .Error(ResponseCode.BackendDatabase, "Error while saving data!"));
                    }
                    return(APIResult <DAL.tbl_vehicles> .Success(value, "API_SUCCESS"));
                }
            }
            catch (Exception ex)
            {
                return(APIResult <DAL.tbl_vehicles> .Error(ResponseCode.BackendDatabase, ex.Message));
            }
        }
Example #23
0
        public ActionResult AssginVehcileToDriver(FormCollection form)
        {
            var vehcile_id = int.Parse(form.Get("vehicle_id") == null?"0": form.Get("vehicle_id"));
            var driver_id  = int.Parse(form.Get("account_id") == null?"0": form.Get("account_id"));

            tbl_drivers_vehicles_rel rel = new tbl_drivers_vehicles_rel()
            {
                vehicle_id = vehcile_id,
                driver_id  = driver_id,
                created_at = DateTime.Now,
                created_by = UserSession.User.user_id,
                status     = 0,
            };

            db.tbl_drivers_vehicles_rel.Add(rel);

            if (db.SaveChanges() <= 0)
            {
                return(Json(new { type = "error", message = "" }));
            }
            tbl_accounts driver = db.tbl_accounts.Include(t => t.sec_users).FirstOrDefault(a => a.id == driver_id);

            return(Json(new { type = "success", message = "Your request sent to " + driver.first_name + " " + driver.last_name + ", Please wait for his action" }));
        }
Example #24
0
        public APIResult <bool> SavePermissions(SavePermissionRequest request)
        {
            using (MainEntities ctx = new MainEntities())
            {
                var deleted = ctx.sec_access_right.Where(a => a.role_id == request.role_id && a.model_name == request.screen);

                foreach (sec_access_right itm in deleted)
                {
                    ctx.Entry(itm).State = System.Data.Entity.EntityState.Deleted;
                }

                if (deleted.Count() > 0)
                {
                    ctx.SaveChanges();
                }


                foreach (var m in request.methods)
                {
                    sec_access_right access = new sec_access_right();
                    access.method_name  = m;
                    access.model_name   = request.screen;
                    access.role_id      = request.role_id;
                    access.force_filter = "";

                    ctx.sec_access_right.Add(access);
                }
                if (ctx.SaveChanges() > 0)
                {
                    return(APIResult <bool> .Success(true, "API_SUCCESS"));
                }
            }


            return(APIResult <bool> .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD", false));
        }
Example #25
0
        public int Saverecords()
        {
            try
            {
                db.SaveChanges();
            }


            catch (DbUpdateException)
            {
                return(500);
            }

            return(200);
        }
Example #26
0
        public APIResult <sec_roles> Post(sec_roles request)
        {
            using (MainEntities ctx = new MainEntities())
            {
                ctx.sec_roles.Add(request);

                if (ctx.SaveChanges() > 0)
                {
                    return(APIResult <sec_roles> .Success(request, "API_SUCCESS"));
                }
            }


            return(APIResult <sec_roles> .Error(ResponseCode.BackendInternalServer, "API_ERROR_BAD"));
        }
Example #27
0
        public APIResult <bool> Delete(int id)
        {
            using (MainEntities ctx = new MainEntities())
            {
                var sec_role = ctx.sec_roles.Find(id);
                ctx.Entry(sec_role).State = System.Data.Entity.EntityState.Deleted;

                if (ctx.SaveChanges() > 0)
                {
                    return(APIResult <bool> .Success(true, "API_SUCCESS"));
                }
            }

            return(APIResult <bool> .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD", false));
        }
Example #28
0
 public void GetDeleteDetail(int?id)
 {
     using (var dbContext = new MainEntities())
     {
         var user = dbContext.UserDetails.Where(x => x.UserId == id).FirstOrDefault();
         var car  = dbContext.CarDetails.Where(x => x.UserId == id).ToList();
         user.IsActive = false;
         dbContext.Entry(user).State = EntityState.Modified;
         if (car.Count() > 0)
         {
             dbContext.CarDetails.RemoveRange(car)
             ;
         }
         dbContext.SaveChanges();
     }
 }
Example #29
0
        public bool resetPassword(Guid ResetPwdKey, string NewPassword)
        {
            using (MainEntities ctx = new MainEntities())
            {
                var user = ctx.sec_users.Where(x => x.reset_pwd_token == ResetPwdKey.ToString()).FirstOrDefault();

                if (user != null)
                {
                    user.pwd              = General.MD5(NewPassword);
                    user.reset_pwd_token  = null;
                    ctx.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Example #30
0
        public static APIResult <MobileVerifyResponse> VerifyMobile(string phone, string otp)
        {
            using (MainEntities ctx = new MainEntities())
            {
                var vm = ctx.sec_mobile_verify.Where(a => a.mobile == phone && a.code == otp).OrderByDescending(a => a.id).FirstOrDefault();
                if (vm == null)
                {
                    return(APIResult <MobileVerifyResponse> .Error(ResponseCode.UserNotFound, "Invalid code or mobile number !!", new MobileVerifyResponse()
                    {
                        is_verified = false
                    }));
                }
                if (vm.is_used == true)
                {
                    return(APIResult <MobileVerifyResponse> .Error(ResponseCode.UserNotFound, "This code is already used !!", new MobileVerifyResponse()
                    {
                        is_verified = false
                    }));
                }
                if (vm.created_at < DateTime.Now.Add(new TimeSpan(0, -10, 0)))
                {
                    return(APIResult <MobileVerifyResponse> .Error(ResponseCode.UserNotFound, "This code expired !!", new MobileVerifyResponse()
                    {
                        is_verified = false
                    }));
                }

                vm.is_used = true;
                Guid guid = Guid.NewGuid();
                vm.verification_id  = guid;
                ctx.Entry(vm).State = System.Data.Entity.EntityState.Modified;

                if (ctx.SaveChanges() == 0)
                {
                    return(APIResult <MobileVerifyResponse> .Error(ResponseCode.BackendDatabase, "API_ERORR_SAVE", new MobileVerifyResponse()
                    {
                        is_verified = false
                    }));
                }
                return(APIResult <MobileVerifyResponse> .Success(new MobileVerifyResponse()
                {
                    is_verified = true, verification_id = guid
                }, "Mobile verified success!"));
            }
        }