private void CollectionInfoForm_Load(object sender, EventArgs e) { lblCollectionName.Text = Control.currentCollection.Name; lblCollectionDescription.Text = Control.currentCollection.Description; lblCreatingDate.Text = Control.currentCollection.CreatingDate.ToShortDateString(); lblAverageMark.Text = Control.currentCollection.AverageMark.ToString(); cbMark.SelectedIndex = 4; CompleteForm.dgvCollectionComments(this); CompleteForm.dgvCollectionCreators(this); CompleteForm.dgvCollectionObjects(this); CompleteForm.dgvCollectionCategories(this); CompleteForm.dgvCollectionMarks(this); }
private void btnAddMark_Click(object sender, EventArgs e) { if (cbMark.Text.Length == 0) { Control.Exclamation("Оценка не выбрана.", "Оценка"); return; } if (Control.currentCollection.Marks.ToList().Exists(x => x.User == Control.currentUser)) { Control.Exclamation("Вы уже ставили оценку этой коллекции.", "Оценка"); return; } Mark newMark = new Mark(); newMark.Value = int.Parse(cbMark.Text); newMark.User = Control.currentUser; newMark.Collection = Control.currentCollection; Control.container.Marks.Add(newMark); Control.currentCollection.Marks.Add(newMark); Control.currentCollection.AverageMark = (double)(from mark in Control.currentCollection.Marks select mark.Value).Sum() / (double)Control.currentCollection.Marks.Count; Collection changingCollection = new Collection(); changingCollection = Control.container.Collections.Find(Control.currentCollection.Id); changingCollection.AverageMark = Control.currentCollection.AverageMark; Control.container.SaveChanges(); CompleteForm.dgvCollectionMarks(this); lblAverageMark.Text = Control.currentCollection.AverageMark.ToString(); }