示例#1
0
        public APIResult <DAL.vwTripsDetails> Current(bool is_rider = false)
        {
            var u = APIRequest.User(HttpContext.Current.Request);

            using (var ctx = new DAL.MainEntities())
            {
                var sTime = DateTime.Now.AddMinutes(180);
                var cDate = DateTime.Now.Date;
                var cTime = DateTime.Now.AddMinutes(-180);

                if (is_rider)
                {
                    var books = ctx.trip_book.Include("trip_request_details").Include("trip_request_details.trip_request").Where(a => a.trip_request_details.trip_request.rider_id == u.Entity.id && a.end_at == null && a.reached_at != null).OrderBy(a => a.id).FirstOrDefault();
                    if (books == null)
                    {
                        return(APIResult <DAL.vwTripsDetails> .Success(null));
                    }
                    return(APIResult <DAL.vwTripsDetails> .Success(ctx.vwTripsDetails.Where(a => a.trip_id == books.trip_share_details_id).OrderByDescending(a => a.trip_id).FirstOrDefault()));
                }
                else
                {
                    return(APIResult <DAL.vwTripsDetails> .Success(ctx.vwTripsDetails.Where(a => a.start_at_date > cTime && a.start_at_date <= sTime && a.is_active == true && a.driver_id == u.Entity.id && ((a.ended_seats < a.started_seats && a.started_seats > 0) || (a.started_seats == 0))).OrderBy(a => a.trip_id).FirstOrDefault()));
                }
            }
        }
示例#2
0
 public APIResult <DAL.vwTripsDetails> Details(int trip_id)
 {
     using (var ctx = new DAL.MainEntities())
     {
         return(APIResult <DAL.vwTripsDetails> .Success(ctx.vwTripsDetails.Where(a => a.trip_id == trip_id && a.is_active == true).FirstOrDefault()));
     }
 }
示例#3
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));
            }
        }
示例#4
0
        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"));
            }
        }
示例#5
0
        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));
            }
        }
示例#6
0
        // 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));
            }
        }
示例#7
0
        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));
            }
        }
示例#8
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"));
        }
示例#9
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));
                }
            }
        }
示例#10
0
        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));
            }
        }
示例#11
0
 public APIResult <IEnumerable <DAL.vwTripSeatDetails> > Details(int trip_id)
 {
     using (var ctx = new DAL.MainEntities())
     {
         return(APIResult <IEnumerable <DAL.vwTripSeatDetails> > .Success(ctx.vwTripSeatDetails.Where(a => a.trip_id == trip_id).ToList()));
     }
 }
示例#12
0
        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"));
            }
        }
示例#13
0
        // 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));
            }
        }
示例#14
0
        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));
            }
        }
示例#15
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));
            }
        }
示例#16
0
        public APIResult <List <string> > RoleMethods(string screen, int role)
        {
            MainEntities ctx = new MainEntities();

            var lst = ctx.sec_access_right.Where(a => a.model_name == screen && a.role_id == role).Select(b => b.method_name).ToList();

            return(APIResult <List <string> > .Success(lst, "API_SUCCESS"));
        }
示例#17
0
        public APIResult <List <DAL.vwSeatsPending> > Pending(int trip_type_id = 0)
        {
            var u = Requests.APIRequest.User(HttpContext.Current.Request);

            using (var ctx = new DAL.MainEntities())
            {
                return(APIResult <List <DAL.vwSeatsPending> > .Success(ctx.vwSeatsPending.Where(a => a.start_at_date > DateTime.Now && a.acc_id == u.Entity.id && (trip_type_id == 0 ? true : a.trip_type_id == trip_type_id)).OrderBy(a => a.start_at_date).ToList()));
            }
        }
示例#18
0
        public APIResult <List <DAL.vwSeatsHistory> > Schedule(int trip_type_id = 0)
        {
            var u = Requests.APIRequest.User(HttpContext.Current.Request);

            using (var ctx = new DAL.MainEntities())
            {
                return(APIResult <List <DAL.vwSeatsHistory> > .Success(ctx.vwSeatsHistory.Where(a => a.start_at_date > DateTime.Now && (a.driver_id == u.Entity.id || a.rider_id == u.Entity.id) && (trip_type_id == 0 ? true : a.trip_type_id == trip_type_id)).ToList()));
            }
        }
示例#19
0
        public APIResult <List <DAL.vwSeatsHistory> > History(int trip_type_id = 0)
        {
            var u = Requests.APIRequest.User(HttpContext.Current.Request);

            using (var ctx = new DAL.MainEntities())
            {
                return(APIResult <List <DAL.vwSeatsHistory> > .Success(ctx.vwSeatsHistory.Where(a => a.ended_at != null && (a.driver_id == u.Entity.id || a.rider_id == u.Entity.id) && (trip_type_id == 0?true:a.trip_type_id == trip_type_id)).OrderByDescending(a => a.ended_at).ToList()));
            }
        }
示例#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));
                }
            }
        }
示例#21
0
        public async Task <APIResult> UserRole(UserRole userRole)
        {
            userRole.GUID = Guid.NewGuid().ToString();
            await db.UserRole.AddAsync(userRole);

            var result = new APIResult();

            result.Success();
            return(result);
        }
示例#22
0
        public APIResult <List <vwProfile> > MyDrivers()
        {
            using (var ctx = new MainEntities())
            {
                var         u           = APIRequest.User(HttpContext.Current.Request);
                List <int?> myDriverIDs = ctx.tbl_drivers_vehicles_rel.Where(a => ctx.tbl_vehicles.Where(b => b.owner_id == u.Entity.id && b.is_delete != true).Select(c => c.id).Contains((int)a.vehicle_id)).Select(a => a.driver_id).Distinct().ToList();

                return(APIResult <List <vwProfile> > .Success(ctx.vwProfile.Where(a => myDriverIDs.Contains(a.id)).ToList()));
            }
        }
示例#23
0
        public APIResult <DAL.vwTripsDetails> Current()
        {
            using (var ctx = new DAL.MainEntities())
            {
                var sTime = DateTime.Now.AddMinutes(60);
                var cDate = DateTime.Now.Date;
                var cTime = DateTime.Now.AddMinutes(-30);

                return(APIResult <DAL.vwTripsDetails> .Success(ctx.vwTripsDetails.Where(a => a.start_at_date < sTime && a.start_at_date > cTime && a.is_active == true).OrderByDescending(a => a.trip_id).FirstOrDefault()));
            }
        }
示例#24
0
        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"));
        }
示例#25
0
 /// <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!"));
 }
示例#26
0
        /// <summary>
        /// add
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        public async Task <APIResult> Add(SystemLog add)
        {
            add.ID         = Guid.NewGuid().ToString();
            add.CreateTime = DateTime.Now;
            await db.SystemLog.AddAsync(add);

            await db.SaveChangesAsync();

            var result = new APIResult();

            result.Success();
            return(result);
        }
示例#27
0
        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));
            }
        }
示例#28
0
        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));
        }
示例#29
0
        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"));
        }
示例#30
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 !"));
            }
        }