Esempio n. 1
0
 public int Save(Inator Inator)
 {
     if (Inator.InatorId > 0) {
         this.db.Inators.Attach(Inator);
         this.db.Entry(Inator).State = EntityState.Modified;
     } else {
         this.db.Inators.Add(Inator);
     }
     return this.db.SaveChanges();
 }
Esempio n. 2
0
 public IActionResult Edit(int id)
 {
     Inator inator = this.inatorRepository.GetById(id);
     if (inator == null) {
         if (id < 1) {
             inator = new Inator {UserId = this.userCurrentService.UserId ?? 0};
         } else {
             return View("NotFound");
         }
     }
     if (inator.UserId != this.userCurrentService.UserId && !this.userCurrentService.IsAdmin) {
         return this.View("NotFound"); // You don't own it therefore it doesn't exist for you
     }
     return this.View(inator);
 }
Esempio n. 3
0
 public IActionResult Edit(int id, Inator Model)
 {
     if (!this.ModelState.IsValid) {
         return this.View(Model); // fix your errors
     }
     Inator inator = this.inatorRepository.GetById(id);
     if (inator == null) {
         if (id < 1) {
             inator = new Inator { UserId = this.userCurrentService.UserId ?? 0 };
         } else {
             return View("NotFound");
         }
     }
     if (inator.UserId != this.userCurrentService.UserId && !this.userCurrentService.IsAdmin) {
         return this.View("NotFound"); // You don't own it therefore it doesn't exist for you
     }
     inator.Subdomain = Model.Subdomain;
     this.inatorRepository.Save(inator);
     return RedirectToAction("Index");
 }