protected virtual void OnPropertiesClicked(object sender, System.EventArgs e) { object cur = addressview.GetCurrentObject(); if (cur == null) return; if (cur is Address) { na = (Address) cur; NewAddress dlg = new NewAddress (na); dlg.Run(); dlg = null; } else { ng = (AddressGroup) cur; NewGroup dlg = new NewGroup (ng); dlg.Run(); dlg = null; } }
public string Get(int id) { try { string sql = string.Format(@"SELECT g.Id, g.Club, g.GroupName, g.Leader, u.FirstName, u.LastName, g.DefaultHours, SUM(r.Duration) FROM Groups g LEFT OUTER JOIN Users u ON g.Leader = u.UserId LEFT OUTER JOIN Realizations r ON g.Id = r.GroupId WHERE g.Id = {0} GROUP BY g.Id, g.Club, g.GroupName, g.Leader, u.FirstName, u.LastName, g.DefaultHours ORDER BY g.Club ASC", id); NewGroup x = new NewGroup(); using (SqlConnection connection = new SqlConnection(G.connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { x = ReadData(reader); } ; } } connection.Close(); } return(JsonConvert.SerializeObject(x, Formatting.None)); } catch (Exception e) { return(JsonConvert.SerializeObject(e.Message, Formatting.None)); } }
public List <NewGroup> LoadData() { string sql = @"SELECT g.Id, g.Club, g.GroupName, g.Leader, u.FirstName, u.LastName, g.DefaultHours, SUM(r.Duration) FROM Groups g LEFT OUTER JOIN Users u ON g.Leader = u.UserId LEFT OUTER JOIN Realizations r ON g.Id = r.GroupId GROUP BY g.Id, g.Club, g.GroupName, g.Leader, u.FirstName, u.LastName, g.DefaultHours ORDER BY g.Club ASC"; List <NewGroup> xx = new List <NewGroup>(); using (SqlConnection connection = new SqlConnection(G.connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { NewGroup x = ReadData(reader); xx.Add(x); } } } connection.Close(); } return(xx); }
protected bool Check(NewGroup x) { try { int count = 0; string sql = string.Format("SELECT COUNT([Id]) FROM Groups WHERE Club = '{0}' AND GroupName = '{1}'", x.club, x.groupName); using (SqlConnection connection = new SqlConnection(G.connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { count = G.ReadI(reader, 0); } } } connection.Close(); } if (count == 0) { return(true); } else { return(false); } } catch (Exception e) { return(false); } }
public IActionResult AddGroup([FromBody] NewGroup newGroup) { int userID = int.Parse(User.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value); groupService.AddGroup(userID, newGroup); return(Ok()); }
public string Save(NewGroup x) { if (x.id == null && Check(x) == false) { return(JsonConvert.SerializeObject("Grupa je već registrirana", Formatting.None)); } else { try { using (SqlConnection connection = new SqlConnection(G.connectionString)) { connection.Open(); string sql = null; if (x.id == null) { sql = string.Format(@"INSERT INTO Groups (Club, GroupName, Leader, DefaultHours) VALUES ('{0}', '{1}', '{2}', '{3}')", x.club, x.groupName, x.leaderId, x.defaultHours); } else { sql = string.Format(@"UPDATE Groups SET Club = '{0}', GroupName = '{1}', Leader = '{2}', DefaultHours = '{3}' WHERE Id = '{4}'", x.club, x.groupName, x.leaderId, x.defaultHours, x.id); } using (SqlCommand command = new SqlCommand(sql, connection)) { command.ExecuteNonQuery(); } connection.Close(); } return(JsonConvert.SerializeObject(LoadData(), Formatting.None)); } catch (Exception e) { return(JsonConvert.SerializeObject(e.Message, Formatting.None)); } } }
public void AddGroup_ValidCall() { var users = GetSampeUsers().AsQueryable(); var mockGroupsSet = new Mock <DbSet <Group> >(); var mockUsersSet = new Mock <DbSet <User> >(); mockUsersSet.As <IQueryable <User> >().Setup(m => m.Provider).Returns(users.Provider); mockUsersSet.As <IQueryable <User> >().Setup(m => m.Expression).Returns(users.Expression); mockUsersSet.As <IQueryable <User> >().Setup(m => m.ElementType).Returns(users.ElementType); mockUsersSet.As <IQueryable <User> >().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator()); var mockContext = new Mock <MailBoxDBContext>(); mockContext.Setup(c => c.Users).Returns(mockUsersSet.Object); mockContext.Setup(c => c.Groups).Returns(mockGroupsSet.Object); var service = new GroupService(mockContext.Object); NewGroup newGroup = new NewGroup { Name = "newgroup" }; service.AddGroup(9, newGroup); mockGroupsSet.Verify(m => m.Add(It.IsAny <Group>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
protected virtual void OnNewgroupClicked(object sender, System.EventArgs e) { ng = new AddressGroup("untitled"); NewGroup dlg = new NewGroup (ng); dlg.Run(); list.Add (ng); dlg = null; }
protected virtual void OnNewgroupClicked(object sender, System.EventArgs e) { ng = new AddressGroup("untitled"); NewGroup dlg = new NewGroup(ng); dlg.Run(); list.Add(ng); dlg = null; }
public NewItem() { InitializeComponent(); //source.Add(new Member() { Name = "John" }); //source.Add(new Member() { Name = "Eric" }); //source.Add(new Member() { Name = "Yue Weng" }); //source.Add(new Member() { Name = "Georgii" }); //this.listPicker.ItemsSource = source; group = GlobalVars.group; GlobalVars.group = null; }
public void Group() { if (this._root.SelectedNode.Text == "Principal") { var newGroup = new NewGroup(this._root); newGroup.ShowDialog(); } else { MessageBox.Show("Não é possível criar subgrupos!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void AddGroup(int ownerID, NewGroup newGroup) { User owner = _context.Users.Where(u => u.ID == ownerID).FirstOrDefault(); Group createdGroup = new Group { Owner = owner, GroupName = newGroup.Name }; _context.Groups.Add(createdGroup); _context.SaveChanges(); }
public void ConstructorTest() { #region Init variables string name = "testname"; #endregion NewGroup newGroup = new NewGroup { Name = name }; #region Tests Assert.NotNull(newGroup); Assert.Equal(newGroup.Name, name); #endregion }
public string Init() { NewGroup x = new NewGroup(); x.id = null; x.club = G.club; x.groupName = null; x.leaderId = null; x.leaderFirstName = null; x.leaderLastName = null; x.defaultHours = 0; x.totalHours = 0; return(JsonConvert.SerializeObject(x, Formatting.None)); }
private NewGroup ReadData(SqlDataReader reader) { NewGroup x = new NewGroup(); x.id = G.ReadI(reader, 0); x.club = G.ReadS(reader, 1); x.groupName = G.ReadS(reader, 2); x.leaderId = G.ReadI(reader, 3); x.leaderFirstName = G.ReadS(reader, 4); x.leaderLastName = G.ReadS(reader, 5); x.defaultHours = G.ReadI(reader, 6); x.totalHours = G.ReadI(reader, 7); return(x); }
/// <summary> /// Get Group Chat Object /// </summary> /// <param name="gcu">NewGroup Object</param> /// <returns></returns> internal GroupChat Get(NewGroup gcu) { if (!GroupChats.ContainsKey(gcu.ID)) { GroupChat chat = new GroupChat(gcu.Name); GroupChats.Add(gcu.ID, chat); chat.InviteToGroup += (u) => GroupUser(new GroupUser(gcu.ID, u), true); chat.KickFromGroup += (u) => GroupUser(new GroupUser(gcu.ID, u), false); chat.sendMessage += (s) => SendMessage(s, gcu.ID); chat.leaveChat += () => { Close(gcu.ID); WriteToServer(Status.GroupLeave, gcu.ID); }; return(chat); } return(null); }
public string Delete(NewGroup x) { try { string sql = string.Format(@"DELETE FROM Groups WHERE Id = {0}", x.id); using (SqlConnection connection = new SqlConnection(G.connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(sql, connection)) { command.ExecuteNonQuery(); } connection.Close(); } return(JsonConvert.SerializeObject(LoadData(), Formatting.None)); } catch (Exception e) { return(JsonConvert.SerializeObject(e.Message, Formatting.None)); } }
private void Add() { var context = new GroupVM(departments.ToArray()); var wing = new NewGroup() { DataContext = context }; wing.ShowDialog(); System.Console.WriteLine(context.Group != null); if (context.Group != null) { ClassGroups.Add(context.Group); } }
public IHttpActionResult CreateGroup(NewGroup newGroup) { if (newGroup == null) { throw new ArgumentNullException("newGroup"); } if (string.IsNullOrWhiteSpace(newGroup.Name)) { throw new ArgumentException("Group name must be defined."); } Group group = mapperFactory.CreateGroupMapper() .Map(identityManagementService.CreateGroup(newGroup.Name, newGroup.Description, newGroup.ExternalGroupName)); return(Ok(group)); }
public void WhenGroupNameIsCorrect_ShouldNotHaveAnyError() { var validator = new NewGroupValidator(); #region Init variables string name = "testname"; #endregion NewGroup newGroup = new NewGroup { Name = name }; var result = validator.TestValidate(newGroup); #region Tests result.ShouldNotHaveAnyValidationErrors(); #endregion }
public void WhenGroupNameIsEmpty_ShouldHaveError() { var validator = new NewGroupValidator(); #region Init variables string name = ""; #endregion NewGroup newGroup = new NewGroup { Name = name }; var result = validator.TestValidate(newGroup); #region Tests result.ShouldHaveValidationErrorFor(x => x.Name); #endregion }
private void Edit() { if (Index >= 0) { var group = ClassGroups[Index]; var context = new GroupVM(group, departments.ToArray()); var wind = new NewGroup() { DataContext = context }; wind.ShowDialog(); if (context.Group != null) { ClassGroups[Index] = context.Group; } } }
public ProductsBySupplierItem[] ProductsBySupplier() { using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { var productsBySupplier = (from p in db.Products group p by new { p.SupplierName } into NewGroup select new ProductsBySupplierItem() { Count = NewGroup.Count(), Supplier = NewGroup.Key.ToString() } ).ToArray(); return(productsBySupplier); } }
public async Task CreateGroup(long userId, NewGroup newGroup) { using (var transaction = Context.Database.BeginTransaction(System.Data.IsolationLevel.Serializable)) { try { var existingGroup = await Context.Groups .SingleOrDefaultAsync(x => x.CreatorUserId == userId && x.Name == newGroup.Name); if (existingGroup != null) { throw new BusinessException("name_taken"); } var daoGroup = new DaoGroup() { CreatorUserId = userId, Name = newGroup.Name }; await Context.Groups.AddAsync(daoGroup); if (await Context.SaveChangesAsync() != 1) { throw new DatabaseException("group_not_created"); } await History.LogCreateGroup(userId, daoGroup); if (await Context.SaveChangesAsync() != 1) { throw new DatabaseException("group_create_history_not_saved"); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } }
private void Add() { var context = new GroupVM(departments.ToArray()); var wind = new NewGroup() { DataContext = context }; wind.ShowDialog(); if (wind.DialogResult == true) { if (context.Group != null) { if (RequestToDataBase.Instance.requestInsertIntoGroup(context.Group)) { ClassGroups.Add(context.Group); } } } }
private static async Task <UnifiedGroup> CreateGroup(string groupName, string desc, string nickname, string accessToken) { var newGroup = new NewGroup(); newGroup.Description = desc; newGroup.DisplayName = groupName; newGroup.GroupTypes = new List <string>(); newGroup.GroupTypes.Add("Unified"); newGroup.MailEnabled = true; newGroup.SecurityEnabled = false; newGroup.MailNickname = nickname; string requestUrl = "https://graph.microsoft.com/v1.0/groups"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); request.Content = new StringContent(JsonConvert.SerializeObject(newGroup), Encoding.UTF8, "application/json"); using (var httpClient = new HttpClient()) { HttpResponseMessage response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { string responseString = await response.Content.ReadAsStringAsync(); UnifiedGroup group = JsonConvert.DeserializeObject <UnifiedGroup>(responseString); return(group); } else { // Something went wrong... throw new Exception(await response.Content.ReadAsStringAsync()); } } }
public void CreateButtonPress() { if (iGroupName.text != "" && iGroupDesc.text != "" && iGroupDays.text != "") { NewGroup newGroup = new NewGroup(iGroupName.text, iGroupDesc.text, int.Parse(iGroupDays.text)); PlayerPrefs.SetString("newGroupName", newGroup.groupName); PlayerPrefs.SetString("newGroupDesc", newGroup.groupDescription); PlayerPrefs.SetInt("newGroupTimer", newGroup.groupDays); sMS.SwitchToMainScreen(); } if (iGroupName.text == "") { iGroupName.placeholder.color = new Color(255, 0, 0); } if (iGroupDesc.text == "") { iGroupDesc.placeholder.color = new Color(255, 0, 0); } if (iGroupDays.text == "") { iGroupDays.placeholder.color = new Color(255, 0, 0); } }
protected virtual void OnPropertiesClicked(object sender, System.EventArgs e) { object cur = addressview.GetCurrentObject(); if (cur == null) { return; } if (cur is Address) { na = (Address)cur; NewAddress dlg = new NewAddress(na); dlg.Run(); dlg = null; } else { ng = (AddressGroup)cur; NewGroup dlg = new NewGroup(ng); dlg.Run(); dlg = null; } }
public async Task CreateGroup(long userId, NewGroup newGroup) { var existingGroup = await _context.Groups .FirstOrDefaultAsync(x => x.CreatorUserId == userId && x.Name == newGroup.Name); if (existingGroup != null) { throw new Exceptions.BusinessException("name_taken"); } await _context.Groups.AddAsync(new DaoGroup() { CreatorUserId = userId, Name = newGroup.Name }); if (await _context.SaveChangesAsync() != 1) { throw new Exceptions.DatabaseException("group_not_created"); } }
private void Edit() { if (Index >= 0) { var group = ClassGroups[Index]; var context = new GroupVM(group, departments.ToArray()); var wind = new NewGroup() { DataContext = context }; wind.ShowDialog(); if (wind.DialogResult == true) { if (context.Group != null) { if (RequestToDataBase.Instance.requestUpdateGroup(context.Group, ClassGroups, Index)) { ClassGroups[Index] = context.Group; } } } } }
private void AddGroup_OnClick(object sender, RoutedEventArgs e) { NewGroup?.Invoke(sender, e); }
public static void ListResources(Farm farm, string id, string type) { IEnumerable <GrazingField> CorrectFieldEnumerable = from field in farm.GrazingFields where field.ShortId == id select field; List <GrazingField> CorrectFieldList = CorrectFieldEnumerable.ToList(); GrazingField CorrectField = CorrectFieldList[0]; IEnumerable <GrazingFieldReport> OrderedAnimals = (from animal in CorrectField.animalsList group animal by animal.Type into NewGroup select new GrazingFieldReport { AnimalType = NewGroup.Key, Number = NewGroup.Count().ToString() } ); List <GrazingFieldReport> AnimalList = OrderedAnimals.ToList(); int count = 1; Console.WriteLine(); Console.WriteLine("The following is in the Grazing Field:"); Console.WriteLine(); foreach (GrazingFieldReport animal in AnimalList) { Console.WriteLine($"{count}: {animal.Number} {animal.AnimalType}"); count++; } Console.WriteLine(); Console.WriteLine("Which resource should be processed?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); int correctedChoice = choice - 1; string AnimalType = AnimalList[correctedChoice].AnimalType; Console.WriteLine($"How many {AnimalType} should be processed? (Max 7)"); int amountToProcess = Int32.Parse(Console.ReadLine()); if (amountToProcess > 7) { Console.WriteLine("Learn to read, dumbass"); amountToProcess = Int32.Parse(Console.ReadLine()); } if (amountToProcess <= 7) { farm.ProcessingList.Add(new ToProcess { FacilityId = CorrectField.ShortId, Type = AnimalType, AmountToProcess = amountToProcess }); Console.WriteLine("Ready to process? (Y/n)"); Console.Write("> "); string input = Console.ReadLine(); switch (input) { case "Y": break; case "n": ChooseMeatProcessor.CollectInput(farm); break; default: break; } } }
public IHttpActionResult CreateGroup(NewGroup newGroup) { if (newGroup == null) { throw new ArgumentNullException("newGroup"); } if (string.IsNullOrWhiteSpace(newGroup.Name)) { throw new ArgumentException("Group name must be defined."); } Group group = mapperFactory.CreateGroupMapper() .Map(identityManagementService.CreateGroup(newGroup.Name, newGroup.Description, newGroup.ExternalGroupName)); return Ok(group); }
public static void CollectInput(Farm farm, int number, string plantType) { Console.Clear(); if (atCapacity) { atCapacity = false; Console.WriteLine($@" **** That facililty is not large enough **** **** Please choose another one ****"); for (int i = 0; i < farm.NaturalFields.Count; i++) { Console.Write($"{i + 1}. Natural Field "); IEnumerable <NaturalFieldReport> NaturalFlowers = (from flower in farm.NaturalFields[i].plantsList group flower by flower.Type into NewGroup select new NaturalFieldReport { PlantType = NewGroup.Key, Number = NewGroup.Count().ToString() } ); foreach (NaturalFieldReport flower in NaturalFlowers) { Console.Write($@"({flower.Number} {flower.PlantType})"); } if (farm.NaturalFields[i].plantsList.Count < farm.NaturalFields[i].Capacity) { // Console.WriteLine($"{i + 1}. Natural Field ({farm.NaturalFields[i].plantsList.Count}/{farm.NaturalFields[i].Capacity})"); } Console.WriteLine("\n"); } Console.WriteLine(); // How can I output the type of animal chosen here? Console.WriteLine($"Place the plant where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); int correctedChoice = choice - 1; farm.NaturalFields[correctedChoice].AddResource(farm, number, plantType); } //runs the code if you don't need the at capacity message else { atCapacity = false; for (int i = 0; i < farm.NaturalFields.Count; i++) { Console.Write($"{i + 1}. Natural Field "); IEnumerable <NaturalFieldReport> NaturalFlowers = (from flower in farm.NaturalFields[i].plantsList group flower by flower.Type into NewGroup select new NaturalFieldReport { PlantType = NewGroup.Key, Number = NewGroup.Count().ToString() } ); foreach (NaturalFieldReport flower in NaturalFlowers) { Console.Write($@"({flower.Number} {flower.PlantType})"); } if (farm.NaturalFields[i].plantsList.Count < farm.NaturalFields[i].Capacity) { // Console.WriteLine($"{i + 1}. Natural Field ({farm.NaturalFields[i].plantsList.Count}/{farm.NaturalFields[i].Capacity})"); } Console.WriteLine("\n"); } Console.WriteLine("\n"); // How can I output the type of animal chosen here? Console.WriteLine($"Place the plant where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); //corrects the users choice to match the correct index int correctedChoice = choice - 1; farm.NaturalFields[correctedChoice].AddResource(farm, number, plantType); } /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<ICompostProducing>(animal, choice); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); //members = GlobalVars.members; //GlobalVars.members = null; if (GlobalVars.item != null) { NewItem load = GlobalVars.item; this.item_id = load.item_id; this.group = load.group; this.item_name.Text = load.item_name.Text; this.textBox_description.Text = load.textBox_description.Text; this.textBox_total.Text = load.textBox_total.Text; this.checkBox_splitEven.IsChecked = load.checkBox_splitEven.IsChecked; this.datePicker_date = load.datePicker_date; textBlocks.Clear(); textBoxes.Clear(); //this.listPicker.ItemsSource = load.listPicker.ItemsSource; this.listPicker.ItemsSource = group.Members; loadSpecifics(load); isEditing = true; GlobalVars.item = null; } else if(GlobalVars.fileNameFull != null || GlobalVars.fileNameThumb != null) { fileNameFull = GlobalVars.fileNameFull; GlobalVars.fileNameFull = null; fileNameThumb = GlobalVars.fileNameThumb; GlobalVars.fileNameThumb = null; } //else if (GlobalVars.selectedMembers != null && GlobalVars.selectMode != null) //{ // if (GlobalVars.selectMode.Equals("payers")) // listPicker_payers.ItemsSource = GlobalVars.selectedMembers; // //else if(GlobalVars.selectMode.Equals("owers")) // GlobalVars.selectedMembers = null; // GlobalVars.selectMode = null; //} else { try { string msg = NavigationContext.QueryString["msg"]; this.item_name.Text = msg; this.listPicker.ItemsSource = group.Members; } catch (KeyNotFoundException ex) { //do nothing } } this.textBox_itemName.Text = this.item_name.Text; }