private void SaveInternal(Achivment achivment) { var now = DateTime.UtcNow; using (var contextScope = ContextScopeFactory.Create()) { var domainAchivment = _mapper.Map <Faw.Models.Domain.Achivment>(achivment); domainAchivment.UpdatedOn = domainAchivment.CreatedOn = now; _achivmentRepository.Save(domainAchivment); var expIds = domainAchivment.ExpressionProperties.Select(x => x.EntityId); var toRemove = _expressionPropertyRepository.GetWhere( x => !expIds.Contains(x.EntityId) && x.AchivmentId == domainAchivment.EntityId) .Select(x => x.EntityId); _expressionPropertyRepository.DeleteRange(toRemove); EditAchivmentProperties(domainAchivment.ExpressionProperties, domainAchivment.EntityId); contextScope.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { Achivment achivment = db.Achivments.Find(id); db.Achivments.Remove(achivment); db.SaveChanges(); return(RedirectToAction("Index")); }
public EditAchivmentDialog(int id) { CurrentAchivmentId = id; InitializeComponent(); l = context.Achivments.FirstOrDefault(g => g.AchivmentId == CurrentAchivmentId); NewName.Text = l.Name; Result.Text = l.Result; Desc.Text = l.Description; }
public ActionResult Edit([Bind(Include = "AchivmentID,GameID,AchivmentTitle,AchivmentDescription")] Achivment achivment) { if (ModelState.IsValid) { db.Entry(achivment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GameID = new SelectList(db.Games, "ID", "Title", achivment.GameID); return(View(achivment)); }
public ActionResult Create([Bind(Include = "AchivmentID,GameID,AchivmentTitle,AchivmentDescription")] Achivment achivment) { if (ModelState.IsValid) { db.Achivments.Add(achivment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GameID = new SelectList(db.Games, "ID", "Title", achivment.GameID); return(View(achivment)); }
public ActionResult AddAchivment(AchivmentViewModel achivment) { Achivment achiv = Mapper.Map <AchivmentViewModel, Achivment>(achivment); ApplicationDbContext db = new ApplicationDbContext(); db.Achivments.Add(achiv); db.SaveChanges(); return(RedirectToAction("AchivmentsEditView")); }
// GET: Achivments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Achivment achivment = db.Achivments.Find(id); if (achivment == null) { return(HttpNotFound()); } return(View(achivment)); }
// GET: Achivments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Achivment achivment = db.Achivments.Find(id); if (achivment == null) { return(HttpNotFound()); } ViewBag.GameID = new SelectList(db.Games, "ID", "Title", achivment.GameID); return(View(achivment)); }
private void AddAchivment(object sender, RoutedEventArgs e) { var learning = context.Learnings.Include(g => g.Section).FirstOrDefault(g => g.LearningId == CurrentLearningId); var id = learning.Section.SectionId; var section = context.Sections.FirstOrDefault(s => s.SectionId == id); if (NewName.Text.Length == 0 || Result.Text.Length == 0 || Desc.Text.Length == 0 || Level.Text == null || Type.Text == null || dialog.FileName.Length == 0) { MessageBox.Show("Empty"); return; } var achiv = new Achivment() { Name = NewName.Text, Result = Result.Text, Description = Desc.Text, Level = Level.SelectedItem as string, Type = Type.SelectedItem as string, Image = ImageName.Text }; learning.Achivments.Add(achiv); section.Achivments.Add(achiv); var task = Task <int> .Factory.StartNew(() => { return(context.SaveChanges()); }); task.Wait(); // MessageBox.Show(task.IsCompleted ? "Выполнено" : "Ошибка создания"); var w = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); w.Body.Content = new Learnings(id); Close(); }
public IHttpActionResult Update([FromBody] Achivment achivment) { _achivmentsService.Update(achivment); return(Ok()); }
public void Update(Achivment achivment) { SaveInternal(achivment); }