public async Task <APIResult <bool> > CheckPhone(string phone, string countryCode = "20") { string validPhone = ""; if (!General.ValidateMobile(phone, out validPhone, countryCode)) { return(APIResult <bool> .Error(ResponseCode.UserValidationField, "Invalid mobile number !")); } using (MainEntities ctx = new MainEntities()) { int countAcc = ctx.tbl_accounts.Count(a => a.mobile == validPhone); if (countAcc > 0) { //var v = await SendVerifyCode(validPhone); //if (v.isSuccess) return(APIResult <bool> .Success(true, "Phone already exists")); //else // return v; } return(APIResult <bool> .Error(ResponseCode.DevNotFound, "Phone not found !", false)); } }
// GET api/values public virtual APIResult <IEnumerable <T> > Get(bool master = false) { try { var data = ctx.Set <T>().ToList(); if (data == null) { return(APIResult <IEnumerable <T> > .Error(ResponseCode.UserNotFound, "Object not found !")); } if (master) { data.ForEach(a => { if (typeof(T).BaseType.Name.Contains("Translate")) { typeof(T).BaseType.GetProperty("GetMasterField").SetValue(a, true); } }); } return(APIResult <IEnumerable <T> > .Success(data, "API_SUCCESS")); } catch (Exception ex) { return(APIResult <IEnumerable <T> > .Error(ResponseCode.BackendDatabase, ex.Message)); } }
public virtual APIResult <T> Post(T value) { try { if (typeof(T).BaseType.Name.Contains("Translate")) { typeof(T).BaseType.GetProperty("GetMasterField").SetValue(value, true); } ctx.Set <T>().Add(value); ctx.Entry(value).State = System.Data.Entity.EntityState.Added; if (ctx.SaveChanges() <= 0) { return(APIResult <T> .Error(ResponseCode.BackendDatabase, "Error while saving data!")); } if (typeof(T).BaseType.Name.Contains("Translate")) { typeof(T).BaseType.GetProperty("GetMasterField").SetValue(value, false); } return(APIResult <T> .Success(value, "API_SUCCESS")); } catch (Exception ex) { return(APIResult <T> .Error(ResponseCode.BackendDatabase, ex.Message)); } }
public APIResult <bool> ChangePassword(PasswordEditRequest request) { var u = APIRequest.User(HttpContext.Current.Request).Entity; //if (request.password != request.cpassword) return APIResult<bool>.Error(ResponseCode.UserValidationField, "Password and confirm not matches !!"); if (request.password.Length < 6) { return(APIResult <bool> .Error(ResponseCode.UserValidationField, "Very short password min (6 chars) !!")); } if (request.current != u.pwd) { return(APIResult <bool> .Error(ResponseCode.UserValidationField, "Invalid current password !!")); } using (var ctx = new DAL.MainEntities()) { var user = ctx.sec_users.Find(u.id); if (request.password == user.pwd) { return(APIResult <bool> .Error(ResponseCode.UserValidationField, "Cannot save new password, It is the same 'Current Password'!!")); } user.pwd = request.password; ctx.Entry(user).State = System.Data.Entity.EntityState.Modified; if (ctx.SaveChanges() > 0) { return(APIResult <bool> .Error(ResponseCode.UserValidationField, "API_SUCCESS")); } return(APIResult <bool> .Error(ResponseCode.UserValidationField, "Cannot save password !!")); } }
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)); } } }
public APIResult <ProfileResponse> Get(int id) { using (var ctx = new DAL.MainEntities()) { ProfileResponse profile = new ProfileResponse(); profile.Account = ctx.vwProfile.Where(a => a.id == id).FirstOrDefault(); if (profile.Account == null) { return(APIResult <ProfileResponse> .Error(ResponseCode.UserNotFound, "This account not found!")); } profile.Vehicles = ctx.tbl_vehicles.Where(a => a.owner_id == profile.Account.id && a.is_delete != true) .Select( c => new VehicleResponse() { data = c, images = new ImagesResponse() { Count = ctx.tbl_images.Where(d => d.model_name == "tbl_vehicles" && d.model_id == c.id && d.model_tag == "main").Count(), Url = (ctx.tbl_images.Where(d => d.model_name == "tbl_vehicles" && d.model_id == c.id && d.model_tag == "main").Count() == 0) ? "" : "/img/scale/tbl_vehicles/" + c.id + "/original/main-{index}.gif" } // .Select(b => "/img/scale/tbl_vehicles/"+ b.model_id + "/original/main-"++".gif").ToList(), }).ToList(); var vchiclesIDs = profile.Vehicles.Select(b => b.data.id).ToList(); var driversIDs = ctx.tbl_drivers_vehicles_rel.Where(a => vchiclesIDs.Contains((int)a.vehicle_id)).Select(c => c.driver_id).ToList(); profile.Drivers = ctx.vwProfile.Where(a => driversIDs.Contains(a.id)).ToList(); return(APIResult <ProfileResponse> .Success(profile, "Data getted success")); } }
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 APIResult <IEnumerable <VehicleResponse> > Drive() { try { var u = APIRequest.User(HttpContext.Current.Request); using (var ctx = new MainEntities()) { var ids = ctx.tbl_drivers_vehicles_rel.Where(a => a.driver_id == u.Entity.id).Select(a => a.vehicle_id).ToList(); var data = ctx.Set <DAL.tbl_vehicles>().Where(a => ids.Contains(a.id) && a.is_delete != true) .Select(img => new VehicleResponse() { data = img, images = new ImagesResponse() { Count = ctx.tbl_images.Where(d => d.model_name == "tbl_vehicles" && d.model_id == img.id && d.model_tag == "main").Count(), Url = (ctx.tbl_images.Where(d => d.model_name == "tbl_vehicles" && d.model_id == img.id && d.model_tag == "main").Count() == 0) ? "" : "/img/scale/tbl_vehicles/" + img.id + "/original/main-{index}.gif" } }).ToList(); if (data == null) { return(APIResult <IEnumerable <VehicleResponse> > .Error(ResponseCode.BackendDatabase, "Error while getting list !")); } return(APIResult <IEnumerable <VehicleResponse> > .Success(data, "API_SUCCESS")); } } catch (Exception ex) { return(APIResult <IEnumerable <VehicleResponse> > .Error(ResponseCode.BackendDatabase, ex.Message)); } }
// GET api/values/5 public APIResult <VehicleResponse> Get(int id) { try { using (var ctx = new MainEntities()) { var data = ctx.Set <DAL.tbl_vehicles>().Find(id); var car = new VehicleResponse() { data = data, images = new ImagesResponse() { Count = ctx.tbl_images.Where(d => d.model_name == "tbl_vehicles" && d.model_id == data.id && d.model_tag == "main").Count(), Url = (ctx.tbl_images.Where(d => d.model_name == "tbl_vehicles" && d.model_id == data.id && d.model_tag == "main").Count() == 0) ? "" : "/img/scale/tbl_vehicles/" + data.id + "/original/main-{index}.gif" } }; if (data == null) { return(APIResult <VehicleResponse> .Error(ResponseCode.BackendDatabase, "Error while getting the vehicle data !")); } return(APIResult <VehicleResponse> .Success(car, "API_SUCCESS")); } } catch (Exception ex) { return(APIResult <VehicleResponse> .Error(ResponseCode.BackendDatabase, ex.Message)); } }
public APIResult <LoginResponse> Current() { var u = APIRequest.User(HttpContext.Current.Request); using (MainEntities ctx = new MainEntities()) { tbl_accounts acc = ctx.tbl_accounts.FirstOrDefault(a => a.id == u.Entity.id); if (u == null || acc == null) { return(APIResult <LoginResponse> .Error(ResponseCode.UserForbidden, "API_ERROR_LOGIN")); } var AuthKey = HttpContext.Current.Request.Headers.GetValues("AUTH_KEY"); LoginResponse l = new LoginResponse(); l.account = acc; l.token = Guid.Parse(AuthKey.First().ToString()); using (MainEntities dal = new MainEntities()) { l.roles = dal.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(l, "API_SUCCESS")); } }
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)); } }
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")); }
public async Task <APIResult <bool> > Canceled(string ids) { int[] book_ids = ids.Split(',').Select(a => int.Parse(a)).ToArray(); if (book_ids.Count() == 0) { return(APIResult <bool> .Error(ResponseCode.UserValidationField, "ids is required !")); } var u = APIRequest.User(HttpContext.Current.Request); using (var ctx = new DAL.MainEntities()) { var lst = ctx.trip_book.Include("trip_share_details").Include("trip_request_details").Where(a => book_ids.Contains(a.id)); foreach (var item in lst) { item.canceled_at = DateTime.Now; item.canceled_by = u.Entity.id; item.trip_share_details.booked_seats++; ctx.Entry(item).State = System.Data.Entity.EntityState.Modified; } bool r = ctx.SaveChanges() > 0; var tripid = lst.FirstOrDefault().trip_share_details.id; var riderIDs = ctx.trip_request.Where(a => lst.Select(s => s.trip_request_details.trip_request_id).Contains(a.id)).Select(a => a.rider_id).ToList(); var driverDeviceID = ctx.sec_sessions.Where(a => riderIDs.Contains(a.user_id)).Select(a => a.device_id).Distinct().ToArray(); await FirebaseNotifications.Send(driverDeviceID, "Seats Canceled", "The driver just canceled your request seats.", new { type = 3, screen = "trip", id = tripid, sender = ctx.vwProfile.FirstOrDefault(a => a.id == u.Entity.id).firebase_uid }); return(APIResult <bool> .Success(r)); } }
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)); } } }
public APIResult <Libs.DataTableResponse <sec_roles> > All(Requests.DataTableRequest request) { Libs.DataTableResponse <sec_roles> response = Libs.DataTableResponse <sec_roles> .getDataTable(Libs.General.getDataTabe(request, "sec_roles")); if (response.data == null) { return(APIResult <Libs.DataTableResponse <sec_roles> > .Error(ResponseCode.BackendInternalServer, "API_ERROR_BAD")); } return(APIResult <Libs.DataTableResponse <sec_roles> > .Success(response, "API_SUCCESS")); }
/// <summary> /// Get one image by ID /// </summary> /// <param name="id">Image ID</param> /// <returns>List Of tbl_mages</returns> public APIResult <tbl_images> Get(int id) { using (MainEntities ctx = new MainEntities()) { tbl_images img = ctx.tbl_images.Where(a => a.id == id).FirstOrDefault(); if (img != null) { return(APIResult <tbl_images> .Success(img, "API_SUCCESS")); } } return(APIResult <tbl_images> .Error(ResponseCode.BackendInternalServer, "Bad Request!")); }
public APIResult <bool> isValid() { var props = this.GetType().GetProperties().Where(a => a.CustomAttributes.Where(at => at.AttributeType.Name == "RequiredAttribute").Count() > 0); foreach (var item in props) { if (item.GetValue(this) == null) { return(APIResult <bool> .Error(ResponseCode.BackendInternalServer, item.CustomAttributes.Where(at => at.AttributeType.Name == "RequiredAttribute").FirstOrDefault().NamedArguments.First(a => a.MemberName == "ErrorMessage").TypedValue.Value.ToString())); } } return(APIResult <bool> .Success(true)); }
public APIResult <sec_roles> Get(int id) { using (MainEntities ctx = new MainEntities()) { var sec_roles = ctx.sec_roles.Find(id); if (sec_roles != null) { return(APIResult <sec_roles> .Success(sec_roles, "API_SUCCESS")); } } return(APIResult <sec_roles> .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD")); }
public APIResult <List <IGrouping <string, tbl_setting> > > AllForEdit() { using (MainEntities ctx = new MainEntities()) { var settings = ctx.tbl_setting.OrderBy(a => a.sequance).GroupBy(a => a.setting_group).ToList(); if (settings == null) { return(APIResult <List <IGrouping <string, tbl_setting> > > .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD")); } return(APIResult <List <IGrouping <string, tbl_setting> > > .Success(settings)); } }
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 !")); } }
internal static APIResult <LoginResponse> LoginByEmail(string email, string password, NameValueCollection serverVariables) { try { using (var ctx = new MainEntities()) { var dbuser = ctx.tbl_accounts.Include("sec_users").Where(a => a.email == email).FirstOrDefault(); if (dbuser == null || dbuser.sec_users.pwd != password) { return(APIResult <LoginResponse> .Error(ResponseCode.UserNotFound, "Invalid login data !")); } //tbl_accounts acc = null; //acc = ctx.tbl_accounts.FirstOrDefault(a => a.id == dbuser.id); var returned = new LoginResponse { account = dbuser }; try { var session = GetNewSession(dbuser.sec_users, serverVariables, 2); if (!session.isSuccess) { return(APIResult <LoginResponse> .Error(session.code, session.message)); } var userSessions = session.data; returned.token = userSessions.id; returned.password = password; returned.roles = ctx.sec_users_roles.Include("sec_roles").Where(a => a.user_id == dbuser.id).Select(b => b.sec_roles.role_key).ToArray(); return(APIResult <LoginResponse> .Success(returned, "Login Success")); } catch (DbEntityValidationException e) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendInternalServer, General.fetchEntityError(e))); } catch (Exception ex) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendInternalServer, ex.Message + " Save Session")); } } } catch (Exception ex) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendInternalServer, ex.Message));; } }
public override void OnActionExecuting(HttpActionContext actionContext) { var USER_ID = HttpContext.Current.Request.Headers.GetValues("AUTH_KEY"); //// For Debug //if (actionContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower() == "user" && actionContext.ActionDescriptor.ActionName.ToLower()=="logout") //{ // var i = ""; //} bool Auth = true; if (USER_ID == null) { Auth = false; //return; } else { string key = USER_ID.First(); Guid token; if (!Guid.TryParse(key, out token)) { Auth = false; } else { Sessions sessions = new Sessions(Guid.Parse(key)); if ( (sessions == null || sessions.Entity == null || sessions.Entity.end_time != null || sessions.Entity.sec_users == null) || sessions.Entity.sec_users.tbl_accounts.is_deleted == true) { Auth = false; } } } if (!Auth) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(APIResult <StringContent> .Error(ResponseCode.UserForbidden, Locales.Locales.translate("API_ERROR_FORBIDDEN"))), System.Text.Encoding.UTF8, "application/json" ), ReasonPhrase = "Critical Exception", }); } }
public APIResult <List <tbl_images> > Get(string model, int model_id, string model_tag = "main") { //var accs = new BL.Accounts.Accounts(); using (MainEntities ctx = new MainEntities()) { var imgs = ctx.tbl_images.Where(a => a.model_id == model_id && a.model_name == model && a.model_tag == model_tag).ToList(); if (imgs != null) { return(APIResult <List <tbl_images> > .Success(imgs, "API_SUCCESS")); } } return(APIResult <List <tbl_images> > .Error(ResponseCode.BackendInternalServer, "API_ERROR_BAD")); }
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)); }
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")); }
public APIResult <List <APIResult <tbl_images> > > Upload(string model, int model_id, string model_tag = "main") { List <APIResult <tbl_images> > dict = new List <APIResult <tbl_images> >(); try { var httpRequest = HttpContext.Current.Request; return(Images.SaveImagesFromRequest(httpRequest, "en", model, model_id, model_tag)); } catch (Exception ex) { string res = string.Format(ex.Message); dict.Add(APIResult <tbl_images> .Error(ResponseCode.BackendDatabase, res)); return(APIResult <List <APIResult <tbl_images> > > .Error(ResponseCode.BackendDatabase, res, dict)); } }
public APIResult <Dictionary <string, object> > General() { var settings = DataAccess.getData("select setting_key, setting_value from tbl_setting where display=1"); if (settings == null) { return(APIResult <Dictionary <string, object> > .Error(ResponseCode.BackendDatabase, "API_ERROR_BAD")); } Dictionary <string, object> rows = new Dictionary <string, object>(); foreach (DataRow item in settings.Rows) { rows.Add((string)item["setting_key"], (string)item["setting_value"]); } return(APIResult <Dictionary <string, object> > .Success(rows, "API_SUCCESS")); }
public async Task <APIResult <MobileVerifyResponse> > VerifyMobile(string Mobile, string Code) { string trueMobile = Mobile; if (General.ValidateMobile(Mobile, out trueMobile)) { Mobile = trueMobile; } else { return(APIResult <MobileVerifyResponse> .Error(ResponseCode.UserValidationField, "Invalid mobile number!")); } var verify = Users.VerifyMobile(Mobile, Code); return(verify); }
public override void OnActionExecuting(HttpActionContext actionContext) { var APP_ID = HttpContext.Current.Request.Headers.GetValues("APP_KEY"); bool Auth = true; if (APP_ID == null) { Auth = false; //return; } else { string key = APP_ID.First(); if (!AppKeys.Contains(key)) { Auth = false; } } if (!Auth) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent( JsonConvert.SerializeObject( APIResult <object> .Error(ResponseCode.DevBadGeteway, "502 Bad Geteway !!") ), System.Text.Encoding.UTF8, "application/json"), ReasonPhrase = "Critical Exception", }); } this.key = APP_ID.First(); if (!hasTrueKey()) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent( JsonConvert.SerializeObject( APIResult <object> .Error(ResponseCode.DevBadGeteway, "502 Bad Geteway !!") ), System.Text.Encoding.UTF8, "application/json"), ReasonPhrase = "Critical Exception", }); } }
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!")); } }