/// POST api/Orgs /// <summary> /// CREATEs a new org, the person who adds it is automatically the admin, only sys admins can add an org /// </summary> public HttpResponseMessage PostOrgs(Orgs orgs) { if (Auth.FB.IsSystemAdmin()) { if (ModelState.IsValid) { // save new org to the Org DB db.Orgs.Add(orgs); db.SaveChanges(); // Map user to the org that was just created and make him the admin db.OrgUserMappings.Add(new OrgUserMappings { usersId = uId, isOrgAdmin = true, orgsId = orgs.id }); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, orgs); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = orgs.id })); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } else { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } }
public Organisation GetOrgByUser(string username) { UserEntity userentity = Users.FirstOrDefault(p => p.Username == username); OrgEntity orgentity = Orgs.FirstOrDefault(p => p.Id == userentity.orgID); return(FromEntity.ToOrg(orgentity)); }
public Organisation GetOrgByUser(Guid userId) { UserEntity userentity = Users.FirstOrDefault(p => p.Id == userId); OrgEntity orgentity = Orgs.FirstOrDefault(p => p.Id == userentity.orgID); return(FromEntity.ToOrg(orgentity)); }
} // the rate for each state (how many ticks before switching a frame) #endregion public SpriteAnalyzer(Hero hero, State state) { Rate = (int)state / 10; //using the rate of each state declared in Global to decide how many ticks pass until the frame switches #region tex and color Tex = Global.cm.Load <Texture2D>(hero.ToString() + "/" + state.ToString()); //accessing the desired sprite Color[] c = new Color[Tex.Width]; //creating a new color array Tex.GetData <Color>(0, new Rectangle(0, Tex.Height - 1, Tex.Width, 1), c, 0, c.Length); //inserting the color from the texture into the color array #endregion #region black List <int> black = new List <int>(); //creating a new list for the locations of the black dots responsible for dividing the sprite for (int i = 0; i < c.Length; i++) //for every pixel in the bottom of the sprite { if (c[i] != c[1]) //if the dot is black { black.Add(i); //add the location of the dot into the list } } #endregion #region recs for (int i = 0; i < black.Count() - 2; i += 2) //for every second black dot in the array starting from the first one besides the last two -- we dont go over the last 2 because for every dot we have to access the two dots after it { Recs.Add(new Rectangle(black[i], 0, black[i + 2] - black[i], Tex.Height - 2)); //make a rectangle starting at the dot and ending two dots after it which marks the frame } #endregion #region orgs for (int i = 1; i < black.Count() - 1; i += 2) // for every second dot starting from the second dot { Orgs.Add(new Vector2(black[i] - black[i - 1], Tex.Height - 2)); // we add every second dot into the orgs array to mark it is and origin for the specific frame } #endregion makeTranBg(); //calling for a function to erase the picture background and make it transparent }
/// DELETE api/Orgs/5 /// <summary> /// DELETEs an entire organization, only a sys admin can do this /// </summary> public HttpResponseMessage DeleteOrgs(int id) { if (Auth.FB.IsSystemAdmin()) { Orgs orgs = db.Orgs.Find(id); if (orgs == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } db.Orgs.Remove(orgs); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, orgs)); } else { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } }
public async Task <ActionResult <string> > Get(string slug) { var org = await Orgs.Find(slug); if (org == null) { return(NotFound()); } return(Ok(Mapper.Map <OrgModel, Org>(org))); }
public async Task <DiscordMessage> SendOrgMessage(CommandContext ctx, Orgs org, string location) { DiscordGuild guild = await ctx.Client.GetGuildAsync(ulong.Parse(org.DiscordId)); var channels = await guild.GetChannelsAsync(); DiscordMessage msg = await channels.First(x => x.Name == "medical-assistance").SendMessageAsync($"Someone Needs Medical Attention \n Approximate location: {location}"); return(msg); }
/// GET api/Orgs/5 /// <summary> /// GETs data about an org by id /// </summary> public Orgs GetOrgs(int id) { Orgs orgs = db.Orgs.Find(id); if (orgs == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(orgs); }
public int AddOrg(DiscordGuild guild) { var orgContext = MultiBotDb.Orgs; var org = new Orgs() { OrgName = guild.Name }; orgContext.Add(org); MultiBotDb.SaveChanges(); return(GetOrgId(guild)); }
public int AddOrg(DiscordGuild guild) { if (MultiBotDb.Orgs.Any(o => o.DiscordId == guild.Id.ToString())) { return(GetOrgId(guild)); } var orgContext = MultiBotDb.Orgs; var org = new Orgs() { OrgName = guild.Name, DiscordId = guild.Id.ToString() }; orgContext.Add(org); MultiBotDb.SaveChanges(); return(GetOrgId(guild)); }
private Akt GetAkt(Orgs org) { int selectedYear = int.Parse(comboBox1.Text); return(new Akt() { bin = org?.BIN?.ToString(), finYear = comboBox1.Text, guCodes = new AktGuCodes { abpCode = org?.KodGU?.ToString().Substring(0, 3), budTypeCode = org?.r_bud_type.code, code = org?.KodGU.ToString() }, orgNameKz = org?.name_kz?.ToString(), orgNameRu = org?.name_ru?.ToString(), yearPlans1 = rep.GetListWhere(r => r.Year == selectedYear).AsEnumerable() .Select(p => MapToYearPlan(p, (int)org?.KodGU)).ToList() }); }
/// PUT api/Orgs/5 /// <summary> /// UPDATE's the orgName if your an admin, currently not in use and returns null /// </summary> public HttpResponseMessage PutOrgs(int id, Orgs orgs) { return(null); }
public override void OnAuthorization(HttpActionContext actionContext) { MyDatabase db = new MyDatabase(); try { // get api token from the user header ApiToken IEnumerable <string> token = actionContext.Request.Headers.GetValues("ApiToken"); _apiToken = token.First(); // get facebook credential based on fb token passed in IEnumerable <string> fbToken = actionContext.Request.Headers.GetValues("FbToken"); Debug.Write(fbToken.First()); _fbToken = fbToken.First(); // Check is user is Legit // authenicated if (_apiToken == _apiTokenSecret) { // the api token is good, is the facebook token valid ? and who are you ? var client = new FacebookClient(_fbToken); dynamic result = client.Get("me", new { fields = "name,id" }); // set the users identity _fbUserid = result.id; var _fbName = result.name; if (_fbUserid != "") { // get the userid (internal id ) from the db - user.Id var user = db.Users.Where(u => u.fbUserId == _fbUserid).FirstOrDefault(); // Brand new user to add if (user == null) { //_isAuth = false; // add user to db Users newUser = new Users(); var now = DateTime.Now.ToString("O"); newUser.defaultOrg = 1; newUser.fbUserId = _fbUserid; newUser.created_at = now; newUser.isSystemAdmin = false; newUser.updated_at = now; newUser.name = _fbName; db.Users.Add(newUser); db.SaveChanges(); // add the user to an org with there name as the orgName Orgs newOrg = new Orgs(); newOrg.created_at = now; newOrg.orgName = _fbName; newOrg.updated_at = now; // save new org to the Org DB db.Orgs.Add(newOrg); db.SaveChanges(); // Map user to the org that was just created and make him the admin db.OrgUserMappings.Add(new OrgUserMappings { usersId = newUser.id, isOrgAdmin = true, orgsId = newOrg.id }); db.SaveChanges(); // set the default org for the user newUser.defaultOrg = newOrg.id; db.SaveChanges(); _userId = newUser.id; // Set up the identity object that our Controllers can use GenericIdentity identity = new GenericIdentity(_fbUserid); System.Threading.Thread.CurrentPrincipal = new GenericPrincipal(identity, _roles); _isAuth = true; } else { _userId = user.id; // Set up the identity object that our Controllers can use GenericIdentity identity = new GenericIdentity(_fbUserid); System.Threading.Thread.CurrentPrincipal = new GenericPrincipal(identity, _roles); _isAuth = true; } } else { _isAuth = false; } } // not authenicated else { _isAuth = false; } //authenicated if (_isAuth) { Debug.WriteLine("You're authenicated"); } // not authenicated else { // 417 - so we can specify a message actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed); actionContext.Response.ReasonPhrase = "Invalid token"; actionContext.Response.Content = new StringContent("Invalid token"); } } catch (FacebookOAuthException e) { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed); actionContext.Response.ReasonPhrase = e.Message; actionContext.Response.Content = new StringContent(e.InnerException.ToString()); } catch (FacebookApiLimitException e) { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed); actionContext.Response.ReasonPhrase = e.Message; actionContext.Response.Content = new StringContent(e.InnerException.ToString()); } catch (FacebookApiException e) { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed); actionContext.Response.ReasonPhrase = e.Message; actionContext.Response.Content = new StringContent(e.InnerException.ToString()); } catch (Exception e) { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed); actionContext.Response.ReasonPhrase = e.Message; actionContext.Response.Content = new StringContent(e.InnerException.ToString()); } finally { db.Dispose(); } }
public Organisation GetOrganisationNameById(int id) { OrgEntity orgentity = Orgs.FirstOrDefault(p => p.Id == id); return(FromEntity.ToOrg(orgentity)); }
public async Task <ActionResult <IEnumerable <Org> > > Get() { return(Ok(Mapper.Map <IEnumerable <OrgModel>, IEnumerable <Org> >(await Orgs.List()))); }
public int GetOrgIdByName(string orgName) { OrgEntity orgEntity = Orgs.FirstOrDefault(p => p.OrgName == orgName); return(orgEntity.Id); }
public IList <string> GetOrganisationNames() { return(Orgs.Select(x => x.OrgName).ToList()); }
public HttpResponseMessage GetWhoAmI(int?s = 0) { // wait for FB to replicate your FBToken System.Threading.Thread.Sleep(500); int uId = Auth.FB.GetUserId(); string fbId = Auth.FB.GetFbId(); try { // what are the orgs you are a member of? var myOrgs = db.OrgUserMappings.Include(oo => oo.Orgs).Where(o => o.usersId == uId); Users u = db.Users.Find(uId); Orgs org = db.Orgs.Find(u.defaultOrg); // are you either a System admin or an admin of at least one org? bool isAdmin = false; if (Auth.FB.IsSystemAdmin()) { isAdmin = true; } else { // determine if the user is an admin of his default org if (Auth.FB.IsOrgAdmin(u.defaultOrg)) { isAdmin = true; } } // if a newFileId is passed in and the user is a member of that org then create a fileInstance, // set the files org as the user deafult org and send back a url #go?file{fileInstId} string referrerUrl = ""; // is new file passed in if (s != 0) { // is user a member of the org? File fileDetails = db.File.FirstOrDefault(ff => ff.id == s); int orgsId = fileDetails.orgsId; if (Auth.FB.IsOrgUser(orgsId)) { int myId = Auth.FB.GetUserId(); // create the file instance NewFileInstance n = new NewFileInstance(); n.fileId = fileDetails.id; n.userId = u.id; n.name = fileDetails.fileName + " - " + u.name + " " + DateTime.Now.ToString("O"); n.created_at = DateTime.Now.ToString("O"); NewFileInstance newFileInst = db.NewFileInstance.Add(n); db.SaveChanges(); //Update the Users default org u.defaultOrg = fileDetails.orgsId; db.Entry(u).State = EntityState.Modified; db.SaveChanges(); // get the first question for url Questions q = db.Questions.FirstOrDefault(dd => dd.fileId == fileDetails.id && dd.order == 1); // pass back file location referrerUrl = "#go?file" + newFileInst.id + "?q" + q.id; isAdmin = Auth.FB.IsOrgAdmin(u.defaultOrg); } else { referrerUrl = ""; } } else { referrerUrl = ""; } return(this.Request.CreateResponse(HttpStatusCode.OK, new { Id = uId, FbUserId = fbId, IsAdmin = isAdmin, org = myOrgs, defaultOrg = u.defaultOrg, defaultOrgName = org.orgName, isSystemAdmin = u.isSystemAdmin, referrerUrl = referrerUrl })); } catch (Exception ex) { return(this.Request.CreateResponse(HttpStatusCode.OK, new { error = ex })); } }
public orgs_editForm() { InitializeComponent(); org = rep.GetList().FirstOrDefault() ?? new Orgs(); }
public Organisation GetOrgByID(int id) { OrgEntity entity = Orgs.FirstOrDefault(x => x.Id == id); return(FromEntity.ToOrg(entity)); }
public async Task SeedDatabase() { try { var deleteuser = await userManager.FindByNameAsync("administrator"); if (deleteuser != null) { return; } var role = new Role() { Id = Guid.NewGuid(), Name = "Administrators" }; var res = await roleManager.CreateAsync(role); long OrgId = 0; if (_OrgRrepo.Queryable().Count() > 0) { OrgId = _OrgRrepo.Queryable().FirstOrDefault().Id; } else { var org = new Orgs() { Name = "شهر سیستم", ParentId = -1 }; _OrgRrepo.Insert(org); OrgId = org.Id; } var user = new User { UserName = "******", Email = "*****@*****.**", Firstname = "مدیر", LastName = "مدیری", OrgId = OrgId, MobileNumber = "00000000000", NationalCode = "0000000000", EmailConfirmed = true, ImageLink = "Admin.png" }; var result = await userManager.CreateAsync(user, "PPpp@123456"); var createrole = await userManager.AddToRoleAsync(user, role.Name); if (result == IdentityResult.Success) { if (_menuRepo.Queryable().Count() == 0) { List <Menu> menus = new List <Menu>(); menus.Add(new Menu() { IsVisible = true, MenuIconName = "fa fa-home", Name = "خانه", Route = "" }); menus.Add( new Menu() { IsVisible = true, MenuIconName = "fa fa-users" , Route = "/", ParentId = -1, Name = "کاربران" }); menus.Add( new Menu() { IsVisible = true, MenuIconName = "fa fa-user", Route = "/users/list", ParentId = 3, Name = "لیست کاربران" }); menus.Add( new Menu() { IsVisible = true, MenuIconName = "fa fa-mask", Route = "/role/createrole", ParentId = 3, Name = "مدیریت نقش ها" }); foreach (var item in menus) { _menuRepo.Insert(item); _menuaccessRepo.Insert(new MenuAccess() { MenuId = item.Id, RoleId = role.Id }); } } } } catch (Exception e) { Console.Write(e.Message); } }
public HttpResponseMessage PostFBUsers(IEnumerable <Users> usr) { //if (ModelState.IsValid) //{ // loop users foreach (Users users in usr) { if (Auth.FB.IsOrgAdmin(users.defaultOrg)) { //Check to see FB ID already exists Users existingUser = db.Users.FirstOrDefault(u => u.fbUserId == users.fbUserId); if (existingUser == null) { // new user // create account Users newUser = new Users(); var now = DateTime.Now.ToString("O"); newUser.defaultOrg = 1; newUser.fbUserId = users.fbUserId; newUser.created_at = now; newUser.isSystemAdmin = false; newUser.updated_at = now; newUser.name = users.name; db.Users.Add(newUser); db.SaveChanges(); // add the user to an org with there name as the orgName Orgs newOrg = new Orgs(); newOrg.created_at = now; newOrg.orgName = users.name; newOrg.updated_at = now; // save new org to the Org DB db.Orgs.Add(newOrg); db.SaveChanges(); // Map user to the org that was just created and make him the admin db.OrgUserMappings.Add(new OrgUserMappings { usersId = newUser.id, isOrgAdmin = true, orgsId = newOrg.id }); // add an org user mapping db.OrgUserMappings.Add(new OrgUserMappings { usersId = newUser.id, isOrgAdmin = users.isSystemAdmin, orgsId = users.defaultOrg }); db.SaveChanges(); // set the default org for the user newUser.defaultOrg = newOrg.id; db.Entry(newUser).State = EntityState.Modified; db.SaveChanges(); } else { // if usr exists // add an org user mapping, if one does not already exist OrgUserMappings existingMapping = db.OrgUserMappings.FirstOrDefault(ou => ou.orgsId == users.defaultOrg && ou.usersId == existingUser.id); if (existingMapping != null) { // update mapping existingMapping.isOrgAdmin = users.isSystemAdmin; db.Entry(existingMapping).State = EntityState.Modified; } else { // create mapping db.OrgUserMappings.Add(new OrgUserMappings { isOrgAdmin = users.isSystemAdmin, orgsId = users.defaultOrg, usersId = existingUser.id }); } db.SaveChanges(); } } } return(Request.CreateResponse(HttpStatusCode.OK)); //} //else //{ // return Request.CreateResponse(HttpStatusCode.BadRequest); //} //else //{ // throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized)); //} }
public IEnumerable <Organisation> FindAllOrgs() { List <OrgEntity> entities = Orgs.ToList(); return(FromEntity.ToOrgList(entities)); }