public ActionResult Create(int? id, SectionPrimitive section) { ViewBag.SectionId = id; section.Parent_Id = id; _servicesFacotry.GetSectionService().CreateOrUpdateSection(section); return View(section); }
public ActionResult Edit(SectionPrimitive section) { if (ModelState.IsValid) { ViewBag.SectionId = section.Parent_Id; _servicesFacotry.GetSectionService().CreateOrUpdateSection(section); } return View(section); }
public ArticlePrimitive CreateOrUpdateArticle(ArticlePrimitive articlePrimitive, SectionPrimitive sectionPrimitive) { try { using (AtSolutionEntities context = new AtSolutionEntities()) { Article entity = articlePrimitive.GetEntity(); Article existingEntity = context.Articles.Where(x => x.Id == articlePrimitive.Id).FirstOrDefault(); //no record of this item in the DB, item being passed in has a PK if (existingEntity == null && entity.Id > 0) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(new Exception("Błąd zapisu do bazy")), "Obiekt nie istniał w bazie, a jego Id jest większe od 0."); } //Item has no PK value, must be new else if (entity.Id <= 0) { context.Articles.AddObject(entity); } //Item was retrieved, and the item passed has a valid ID, do an update else { context.Articles.ApplyCurrentValues(entity); } context.SaveChanges(); return entity; } } catch (Exception e) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message); } }
public static SectionPrimitive GetPrimitiveCopy(this SectionPrimitive primitiveToCopy) { if (primitiveToCopy == null) return null; SectionPrimitive primitive = new SectionPrimitive(); primitive.Id = primitiveToCopy.Id; primitive.Parent_Id = primitiveToCopy.Parent_Id; primitive.Name = primitiveToCopy.Name; primitive.Position = primitiveToCopy.Position; primitive.CreateTime = primitiveToCopy.CreateTime; primitive.DeleteTime = primitiveToCopy.DeleteTime; return primitive; }
public static SectionPrimitive GetPrimitive(this Section entity) { SectionPrimitive primitive = new SectionPrimitive(); primitive.Id = entity.Id; primitive.Parent_Id = entity.Parent_Id; primitive.Name = entity.Name; primitive.Position = entity.Position; primitive.CreateTime = entity.CreateTime; primitive.DeleteTime = entity.DeleteTime; return primitive; }
public void DeleteSection(SectionPrimitive sectionPrimitive) { throw new NotImplementedException(); }