public void DeleteIdea(int ideaId) { IdeasDao i = _ctx.Ideas.First(d => d.IdeaId == ideaId); _ctx.Ideas.Remove(i); _ctx.SaveChanges(); }
private IdeasDao ConvertToDao(Idea obj) { IdeasDao dao = new IdeasDao() { IdeaId = obj.Id, IquestionId = obj.IdeaQuestion.Id, UserId = obj.User.Id, Reported = obj.Reported, ReviewByAdmin = obj.ReviewByAdmin, Title = obj.Title, Visible = obj.Visible, VoteCount = obj.VoteCount, RetweetCount = obj.RetweetCount, ShareCount = obj.ShareCount, Status = obj.Status, VerifiedUser = obj.VerifiedUser, IsDeleted = obj.IsDeleted, ParentId = 0, DeviceId = 0 }; if (obj.ParentIdea != null) { dao.ParentId = obj.ParentIdea.Id; } if (obj.Device != null) { dao.DeviceId = obj.Device.Id; } return(dao); }
private Idea ConvertToDomain(IdeasDao dao) { return(new Idea { Id = dao.IdeaId, IdeaQuestion = new IdeationQuestion { Id = dao.IquestionId }, User = new UimvcUser() { Id = dao.UserId }, Reported = dao.Reported, ReviewByAdmin = dao.ReviewByAdmin, Title = dao.Title, Visible = dao.Visible, VoteCount = dao.VoteCount, RetweetCount = dao.RetweetCount, ShareCount = dao.ShareCount, Status = dao.Status, VerifiedUser = dao.VerifiedUser, IsDeleted = dao.IsDeleted, ParentIdea = new Idea { Id = dao.ParentId }, Device = new IotDevice { Id = dao.DeviceId } }); }
public Idea ReadIdea(int ideaId, bool details) { IdeasDao ideasDao = details ? _ctx.Ideas.AsNoTracking().First(i => i.IdeaId == ideaId) : _ctx.Ideas.First(i => i.IdeaId == ideaId); ExtensionMethods.CheckForNotFound(ideasDao, "Idea", ideaId); return(ConvertToDomain(ideasDao)); }
public void Update(Idea obj) { IdeasDao newIdea = ConvertToDao(obj); IdeasDao foundIdea = _ctx.Ideas.First(i => i.IdeaId == obj.Id); if (foundIdea != null) { foundIdea.Title = newIdea.Title; foundIdea.Reported = newIdea.Reported; foundIdea.ReviewByAdmin = newIdea.ReviewByAdmin; foundIdea.Visible = newIdea.Visible; foundIdea.VoteCount = newIdea.VoteCount; foundIdea.RetweetCount = newIdea.RetweetCount; foundIdea.ShareCount = newIdea.ShareCount; foundIdea.Status = newIdea.Status; foundIdea.VerifiedUser = newIdea.VerifiedUser; foundIdea.DeviceId = newIdea.DeviceId; foundIdea.IsDeleted = newIdea.IsDeleted; _ctx.Ideas.Update(foundIdea); } if (obj.Field != null) { IdeaFieldsDao newTextField = ConvertToDao(obj.Field); IdeaFieldsDao foundTextField = _ctx.IdeaFields.First(f => f.FieldId == obj.Field.Id); if (foundTextField != null) { foundTextField.FieldText = newTextField.FieldText; _ctx.IdeaFields.Update(foundTextField); } } if (obj.Cfield != null) { IdeaFieldsDao newCField = ConvertToDao(obj.Cfield); IdeaFieldsDao foundCField = _ctx.IdeaFields.First(f => f.FieldId == obj.Cfield.Id); if (foundCField != null) { foundCField.FieldStrings = newCField.FieldStrings; _ctx.IdeaFields.Update(foundCField); } } if (obj.Mfield != null) { IdeaFieldsDao newMField = ConvertToDao(obj.Mfield); IdeaFieldsDao foundMField = _ctx.IdeaFields.First(f => f.FieldId == obj.Mfield.Id); if (foundMField != null) { foundMField.LocationX = newMField.LocationX; foundMField.LocationY = newMField.LocationY; foundMField.Url = newMField.Url; _ctx.IdeaFields.Update(foundMField); } } if (obj.Ifield != null) { IdeaFieldsDao newIField = ConvertToDao(obj.Ifield); IdeaFieldsDao foundIField = _ctx.IdeaFields.First(f => f.FieldId == obj.Ifield.Id); if (foundIField != null) { foundIField.Url = newIField.Url; foundIField.UploadedImage = newIField.UploadedImage; _ctx.IdeaFields.Update(foundIField); } } if (obj.Vfield != null) { IdeaFieldsDao newVField = ConvertToDao(obj.Vfield); IdeaFieldsDao foundVField = _ctx.IdeaFields.First(f => f.FieldId == obj.Vfield.Id); if (foundVField != null) { foundVField.Url = newVField.Url; foundVField.UploadedMedia = newVField.UploadedMedia; _ctx.IdeaFields.Update(foundVField); } } _ctx.SaveChanges(); }