public IHttpActionResult PutPortfolio(int id, Portfolio portfolio) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != portfolio.Id) { return(BadRequest()); } db.Entry(portfolio).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PortfolioExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Delete(int id) { if (id < 0) { return(BadRequest("Invalid id")); } using (var context = new PortfolioContext()) { try { var transaction = context.Transactions .Where(t => t.TransactionId == id) .FirstOrDefault(); if (transaction != null) { context.Entry(transaction).State = EntityState.Deleted; context.SaveChanges(); } return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } } }
public async Task <IActionResult> PutSkill(Guid id, Skill skill) { if (id != skill.SkillId) { return(BadRequest()); } _context.Entry(skill).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SkillExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProject(Guid id, Project project) { if (id != project.ProjectId) { return(BadRequest()); } _context.Entry(project).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public Email Delete(Email image) { using (var context = new PortfolioContext()) { context.Entry(image).State = EntityState.Deleted; context.SaveChanges(); return(image); } }
public Project Edit(Project project) { using (var context = new PortfolioContext()) { context.Entry(project).State = EntityState.Modified; context.SaveChanges(); return(project); } }
public ProjectImage Delete(ProjectImage image) { using (var context = new PortfolioContext()) { context.Entry(image).State = EntityState.Deleted; context.SaveChanges(); return(image); } }
public ProjectTechnology Delete(ProjectTechnology technology) { using (var context = new PortfolioContext()) { context.Entry(technology).State = EntityState.Deleted; context.SaveChanges(); return(technology); } }
public Project Delete(int projectId) { using (var context = new PortfolioContext()) { var project = context.Projects.FirstOrDefault(_ => _.ProjectId == projectId); context.Entry(project).State = EntityState.Deleted; context.SaveChanges(); return(project); } }
public ActionResult Edit(Tag tag) { if (ModelState.IsValid) { db.Entry(tag).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tag)); }
public virtual void DeleteElement(T entity, bool saveChanges = true) { _context.Entry(entity).State = EntityState.Modified; _dbSet.Remove(entity); if (saveChanges) { Save(); } }
public ActionResult Edit(ScreenShot screenshot) { if (ModelState.IsValid) { db.Entry(screenshot).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProjectID = new SelectList(db.Projects, "ProjectID", "alias", screenshot.ProjectID); return(View(screenshot)); }
public ActionResult Edit(ProjectTag projecttag) { if (ModelState.IsValid) { db.Entry(projecttag).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProjectID = new SelectList(db.Projects, "ProjectID", "alias", projecttag.ProjectID); ViewBag.TagID = new SelectList(db.Tags, "TagID", "name", projecttag.TagID); return(View(projecttag)); }
public Project Update(int id, string title, string body, string externalLink, HttpPostedFileBase imageFile, ICollection <int> categoryIds) { Project project = _context.Projects.Find(id); try { if (project == null) { throw new ModelNotFoundException("Project not found"); } if (imageFile != null) { string fileName = _imageService.Create(imageFile); project.SetImagePath(fileName); } project.Title = title; project.Body = body; project.ExternalLink = externalLink; _context.Entry(project).State = EntityState.Modified; _context.SaveChanges(); return(project); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(project.ID)) { throw new ModelNotFoundException("Project not found"); } else { throw; } } catch (ImageException e) { Errors = _imageService.Errors; throw new ProjectException(e.Message); } }
public static async Task LoadProjectsIntoPortfolioAsync(this PortfolioContext context, Portfolio portfolio, Expression <Func <Project, bool> > filter = null) { var query = context.Entry(portfolio).Collection(p => p.Projects) .Query() .Include(p => p.Reservation) .Include(p => p.Lead.Team) .Include(p => p.People) .Include(p => p.Category) .Include(p => p.LatestUpdate.Phase) .Include(p => p.FirstUpdate); if (filter != null) { query = query.Where(filter); } await query.LoadAsync(); portfolio.Projects = context.Projects.Local; }
public virtual void Add(T entity) { EntityEntry dbEntityEntry = _context.Entry <T>(entity); _context.Set <T>().Add(entity); }