Example #1
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();
            }
        }
 public ActionResult Edit([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.Entry(tbl_setting).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tbl_setting));
 }
Example #3
0
 public ActionResult Edit([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)
     {
         db.Entry(sec_sessions).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.user_id = new SelectList(db.sec_users, "id", "pwd", sec_sessions.user_id);
     return(View(sec_sessions));
 }
Example #4
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));
            }
        }
        public ActionResult Edit([Bind(Include = "Name,id")] 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 + "]"]);
            }
            //dic.Add("ar", Request.Form["name[ar]"]);

            tbl_genders.name = JsonConvert.SerializeObject(dic);
            tbl_genders.id   = int.Parse(Request.Form["id"]);

            db.Entry(tbl_genders).State = EntityState.Modified;
            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 #6
0
        public APIResult <bool> Delete(int id)
        {
            //var accs = new BL.Accounts.Accounts();

            using (MainEntities ctx = new MainEntities())
            {
                tbl_images img = ctx.tbl_images.Where(a => a.id == id).FirstOrDefault();

                if (img != null)
                {
                    try
                    {
                        ctx.Entry(img).State = System.Data.Entity.EntityState.Deleted;
                        System.IO.File.Delete(HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mediaServer_Path"] + img.large));
                        System.IO.File.Delete(HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mediaServer_Path"] + img.thumb));
                        System.IO.File.Delete(HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mediaServer_Path"] + img.meduim));
                        System.IO.File.Delete(HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mediaServer_Path"] + img.original));
                    }
                    catch (Exception)
                    {
                    }


                    return(APIResult <bool> .Success(true, "API_SUCCESS"));
                }
            }

            return(APIResult <bool> .Error(ResponseCode.BackendInternalServer, "API_ERROR_BAD"));
        }
Example #7
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);
        }
        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"));
            }
        }
Example #9
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 #10
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 #11
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 #12
0
 public ActionResult Edit([Bind(Include = "id,name,role_key,description")] sec_roles sec_roles)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sec_roles).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sec_roles));
 }
Example #13
0
 public ActionResult Edit([Bind(Include = "id,role_id,model_name,method_name,force_filter")] sec_access_right sec_access_right)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sec_access_right).State = EntityState.Modified;
         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 #14
0
 public ActionResult Edit([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.Entry(sec_users).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.id = new SelectList(db.tbl_accounts, "id", "first_name", sec_users.id);
     return(View(sec_users));
 }
        public int UpdateInvoice(string trans_no, string trans_bk, string company_id, saoitrinvhd data)
        {
            if (validate_Existing_Invoice(trans_no, trans_bk, company_id, data))
            {
                return(500);
            }


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

            var old_records = db.saoitrinvdtls.Where(d => d.trans_no == trans_no && d.trans_bk == trans_bk);

            foreach (var ll_currentrow in data.details)
            {
                if (old_records.Any(d => d.serial_no == ll_currentrow.serial_no))
                {
                    db.Entry(ll_currentrow).State = EntityState.Modified;
                }
                else
                {
                    db.saoitrinvdtls.Add(ll_currentrow);
                }
            }

            foreach (var ll_currentrow in old_records)
            {
                if (!data.details.Any(d => d.serial_no == ll_currentrow.serial_no))
                {
                    db.saoitrinvdtls.Remove(ll_currentrow);
                }
            }


            if (PostInvoice(data) != 200)
            {
                return(500);
            }


            return(Saverecords());
        }
 public ActionResult Edit([Bind(Include = "id,user_id,role_id")] sec_users_roles sec_users_roles)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sec_users_roles).State = EntityState.Modified;
         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));
 }
 public ActionResult Edit([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.Entry(tbl_accounts).State = EntityState.Modified;
         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 #18
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 #19
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 #20
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 #21
0
        public ActionResult Edit([Bind(Include = "id,model,color,capacity,owner_id,license_no")] tbl_vehicles tbl_vehicles)
        {
            if (ModelState.IsValid)
            {
                var old = db.tbl_vehicles.Find(tbl_vehicles.id);
                old.model           = tbl_vehicles.model;
                old.color           = tbl_vehicles.color;
                old.license_no      = tbl_vehicles.license_no;
                old.owner_id        = tbl_vehicles.owner_id;
                old.capacity        = tbl_vehicles.capacity;
                db.Entry(old).State = EntityState.Modified;
                db.SaveChanges();

                var httpRequest = Request;
                if (httpRequest.Files.Count > 0)
                {
                    if (!Images.SaveImagesFromRequest(httpRequest, "en", "tbl_vehicles", old.id, "main"))
                    {
                        //return Json(new { type = "success", message = "Upload images success" });
                        return(Json(new { type = "error", message = "Error while upload images" }));
                    }
                }


                if (Request.IsAjaxRequest())
                {
                    return(Json(new { type = "success", message = "" }));
                }
                return(RedirectToAction("Edit", tbl_vehicles.id));
            }
            List <string> errors = new List <string>();

            foreach (var i in ModelState.Values)
            {
                if (i.Errors.Count > 0)
                {
                    errors.AddRange(i.Errors.Select(a => a.ErrorMessage));
                }
            }
            if (Request.IsAjaxRequest())
            {
                return(Json(new { type = "error", message = errors[0], data = errors }));
            }

            return(View(tbl_vehicles));
        }
Example #22
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!"));
            }
        }
Example #23
0
        public APIResult <sec_roles> Put(int id, sec_roles request)
        {
            using (MainEntities ctx = new MainEntities())
            {
                var sec_role = ctx.sec_roles.Find(id);
                sec_role.name        = request.name;
                sec_role.role_key    = request.role_key;
                sec_role.description = request.description;

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

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

            return(APIResult <sec_roles> .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD"));
        }
Example #24
0
        public APIResult <bool> Logout()
        {
            var AuthKey = HttpContext.Current.Request.Headers.GetValues("AUTH_KEY");

            using (MainEntities ctx = new MainEntities())
            {
                var ses = ctx.sec_sessions.Find(Guid.Parse(AuthKey.First().ToString()));
                ses.end_time         = DateTime.Now;
                ses.device_id        = null;
                ctx.Entry(ses).State = System.Data.Entity.EntityState.Modified;

                if (ctx.SaveChanges() == 0)
                {
                    return(APIResult <bool> .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD", false));
                }
            }

            return(APIResult <bool> .Success(true, "API_SUCCESS"));
        }
Example #25
0
        public APIResult <bool> SaveNewDeviceID(String device_id)
        {
            var log = new Sessions(Guid.Parse(HttpContext.Current.Request.Headers.Get("AUTH_KEY")));



            log.Entity.device_id = device_id;
            using (var ctx = new MainEntities())
            {
                ctx.Entry(log.Entity).State = System.Data.Entity.EntityState.Modified;
                try
                {
                    ctx.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(APIResult <bool> .Error(ResponseCode.BackendDatabase, ex.Message));
                }
            }
            return(APIResult <bool> .Success(true));
        }
Example #26
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 #27
0
        public APIResult <List <tbl_setting> > Edit(List <tbl_setting> request)
        {
            using (MainEntities ctx = new MainEntities())
            {
                //var settings = ctx.tbl_setting.Where(a => a.display == true).OrderBy(a => a.setting_group).OrderBy(a => a.setting_key).ToList();
                foreach (var item in request)
                {
                    var entity = ctx.tbl_setting.Find(item.id);

                    entity.setting_value    = item.setting_value;
                    ctx.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                }

                if (ctx.SaveChanges() == 0)
                {
                    return(APIResult <List <tbl_setting> > .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD"));
                }
                Libs.Settings.Load();

                return(APIResult <List <tbl_setting> > .Success(request, "API_SUCCESS"));
            }
        }
Example #28
0
        public APIResult <bool> Delete(int id)
        {
            try
            {
                using (var ctx = new MainEntities())
                {
                    var obj = ctx.Set <DAL.tbl_vehicles>().Find(id);
                    obj.is_delete        = true;
                    ctx.Entry(obj).State = System.Data.Entity.EntityState.Modified;

                    if (ctx.SaveChanges() <= 0)
                    {
                        return(APIResult <bool> .Error(ResponseCode.BackendDatabase, "Error while saving data!", false));
                    }
                    return(APIResult <bool> .Success(true, "API_SUCCESS"));
                }
            }
            catch (Exception ex)
            {
                return(APIResult <bool> .Error(ResponseCode.BackendDatabase, ex.Message));
            }
        }
Example #29
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 #30
0
        public async Task <APIResult <bool> > SendVerifyCode(string Mobile)
        {
            //int uid = APIRequest.User(HttpContext.Current.Request).Entity.id;
            //using (MainEntities ctx = new MainEntities())
            //{
            string trueMobile = Mobile;

            if (General.ValidateMobile(Mobile, out trueMobile))
            {
                Mobile = trueMobile;
            }
            else
            {
                return(APIResult <bool> .Error(ResponseCode.UserValidationField, "Invalid mobile number!"));
            }


            //var dublicated = ctx.tbl_accounts.Include("sec_users").Where(a => a.mobile == Mobile && a.sec_users.phone_verified == true ).Count();

            //if (dublicated > 0)
            //    return APIResult<bool>.Error(ResponseCode.UserDoublicate, "This mobile is already exists in our database!");
            //}

            var sms_url = Settings.AppSetting.FirstOrDefault(a => a.setting_key == "sms_url").setting_value;

            if (sms_url != null && sms_url != "")
            {
                using (var client = new HttpClient())
                {
                    Random random = new Random();
                    var    code   = random.Next(100000, 999999);

                    using (MainEntities ctx = new MainEntities())
                    {
                        DateTime expiredTime = DateTime.Now.Add(new TimeSpan(0, -10, 0));

                        sec_mobile_verify vm = ctx.sec_mobile_verify.Where(a => a.mobile == Mobile && a.is_used == false && a.created_at > expiredTime).OrderByDescending(a => a.id).FirstOrDefault();
                        if (vm != null)
                        {
                            code                = int.Parse(vm.code);
                            vm.created_at       = DateTime.Now;
                            ctx.Entry(vm).State = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {
                            vm            = new sec_mobile_verify();
                            vm.mobile     = Mobile;
                            vm.code       = code.ToString();
                            vm.created_at = DateTime.Now;
                            ctx.sec_mobile_verify.Add(vm);
                        }


                        if (ctx.SaveChanges() > 0)
                        {
                            var uri      = new Uri(sms_url.Replace("##mobile##", Mobile).Replace("##code##", code.ToString()));
                            var response = await client.PostAsJsonAsync(uri, "");

                            var smsResult = await response.Content.ReadAsStringAsync();

                            if (response.IsSuccessStatusCode && smsResult.Contains("success"))
                            {
                                return(APIResult <bool> .Success(true, "API_SUCCESS"));
                            }
                            else
                            {
                                Logger.log(string.Format("SMSErorr: Code={0},Mobile={1} \r\n {2}", code, Mobile, smsResult));
                            }
                        }
                    }
                    return(APIResult <bool> .Error(ResponseCode.BackendInternalServer, "Bad Request!"));
                }
            }
            return(APIResult <bool> .Error(ResponseCode.BackendInternalServer, "API_SUCCESS"));
        }