public ActionResult AddInfo(DescriptionViewModel pValue) { try { var newDescription = new PersonDescription { PersonId = _appContext.LoginId, Description = pValue.Description, }; var existingDescription = _personDescriptionRespository.GetById(pValue.PersonId); if (existingDescription == null || existingDescription.Description == pValue.Description) { _personDescriptionRespository.Add(newDescription); } if (newDescription.Description == null) { _personDescriptionRespository.Delete(existingDescription); } else { existingDescription.PersonId = _appContext.LoginId; existingDescription.Description = pValue.Description; _personDescriptionRespository.Update(existingDescription); } return(new JsonCamelCaseResult(new { Success = true, }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(new JsonCamelCaseResult(new { Success = false, Message = "" }, JsonRequestBehavior.AllowGet)); } }
// // Description // public PersonDescription AddPersonDescription( PersonDescription description) { _context.PersonDescriptions.Add(description); _context.SaveChanges(); return(description); }
private static PersonDescriptionModel GetDescriptionModel(PersonDescription description) { var result = description != null ? new PersonDescriptionModel { Id = description.Id, id_Person = description.id_Person, id_DescriptionType = description.id_DescriptionType, PersonDescriptionType = description.PersonDescriptionType.Name, DescriptionText = description.DescriptionText, Status = description.Status, IdStaticDescription = description.StaticDescription?.Id, IdBlock = description.IdBlock, RequiredStaticDescription = description.RequiredStaticDescription, PageBlock = PageModelHelper.GetPageBlockModel(description.PageBlock), StaticDescription = description.StaticDescription != null?GetDescriptionModel(description.StaticDescription) : null, } : new PersonDescriptionModel(); if (result.PageBlock == null) { return(result); } result.PageBlock.UserPageCategoryId = description?.IdUserPageCategory; result.PageBlock.UserPageCategory = description?.UserPageCategory?.Name; return(result); }
public PersonDescription UpdatePersonDescription( PersonDescription description) { description.TimeLastUpdated = DateTime.Now; _context .Attach(description) .State = EntityState.Modified; _context.SaveChanges(); return(description); }
/// <see cref="IPersonRepository.UpdateDescription" /> public PersonDescription UpdateDescription(PersonDescription description, int userId) { if (description.Id == 0) { db.Entry(description).State = System.Data.Entity.EntityState.Added; } else if (description.Id > 0) { var pr = db.PersonDescriptions.FirstOrDefault(o => o.Id == description.Id); SaveLog(pr, description, description.id_Person, userId, LogType.Description); db.Entry(pr).CurrentValues.SetValues(description); } try { db.SaveChanges(); } catch (Exception e) { return(null); } return(description); }
/// <see cref="IPersonRepository.SaveDescriptionSchema" /> public bool SaveDescriptionSchema(int id, PageBlock pageBlock, UserPageCategory cat, int personId) { cat = SaveUserPageCategory(cat); var page = SavePage(pageBlock.Page); if (page == null) { return(false); } pageBlock.IdPage = page.Id; var pageblock = SavePageBlock(pageBlock); if (pageblock == null) { return(false); } var desc = db.PersonDescriptions.FirstOrDefault(o => o.Id == id); if (desc == null) { desc = new PersonDescription { id_DescriptionType = 1, id_Person = personId }; db.Entry(desc).State = EntityState.Added; } desc.IdBlock = pageblock.Id; desc.IdUserPageCategory = cat?.Id; try { db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public IActionResult Create( Guid personGuid, PersonDescriptionCreateModel createModel) { // Must have an GUID if (personGuid == Guid.Empty) { return(NotFound()); } // Must have a person var person = _personData.ReadPersonWithDescriptions(personGuid); // Do we have what we need so far? if (person == null) { return(NotFound()); } // Page navigation ViewData["PersonGuid"] = person.PersonGuid; // // Validate // var form = new PersonDescriptionModelState( ModelState, new Logic.Validate.PersonDescription( createModel.Text), createModel.Type, person.Descriptions, null); form.HasValidValues(); if (!ModelState.IsValid) { return(View(createModel)); } form.HasUniqueTypeToBeCreated(); if (!ModelState.IsValid) { return(View(createModel)); } // // Create // var newDescription = new PersonDescription(); newDescription.PersonId = person.PersonId; newDescription.Type = (PersonDescriptionType)createModel.Type; newDescription.Description = createModel.Text; try { _personData.AddPersonDescription(newDescription); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError( "", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); return(View(createModel)); } // // Update RDF // var readPerson = _personData.ReadAllPersonData(personGuid); if (readPerson != null) { _rdfData.AddOrUpdatePerson(readPerson); } // // Update search index // // Descriptions are at this time not searchable. // // Redirect // return(RedirectToAction( "Details", "Person", new { personGuid = person.PersonGuid })); }
public void DeletePersonDescription( PersonDescription description) { _context.PersonDescriptions.Remove(description); _context.SaveChanges(); }
public DisplayPersonDescription(PersonDescription personDescription) { PersonDescription = personDescription; }
private void LinkDb(GetticketDBContext context) { context.PersonDescriptionType.AddOrUpdate(o => o.Id, new PersonDescriptionType { Id = 1, Name = "Тизер", Type = DescriptionTypes.Tizer }); context.PersonDescriptionType.AddOrUpdate(o => o.Id, new PersonDescriptionType { Id = 2, Name = "Описание", Type = DescriptionTypes.Description }); context.SaveChanges(); context.PageSchemas.AddOrUpdate(o => o.Id, new PageSchema { Id = 1, IdPerson = 1, Page = PageTypes.Person }); context.SaveChanges(); context.PageBlockTypes.AddOrUpdate(o => o.Id, new PageBlockType { Id = 1, Name = "Другие персоны подборки" }); context.SaveChanges(); context.PageBlocks.AddOrUpdate(o => o.Id, new PageBlock { Id = 1, IdPage = 1, IdBlockType = 1 }); context.SaveChanges(); var staticDesc = new PersonDescription { Id = 1, id_DescriptionType = 2, id_Person = 1, DescriptionText = "Родилась в Москве 6 февраля 1991 года. В возрасте 6 лет она начинает заниматься фигурным катанием в школе ЦСКА, а позже каталась на стадионе «Юных Пионеров», где ее тренировала Федерченко Любовь Анатольевна. Училась Анна в нескольких московских школах, с 2000 по 2005 в школе No73, а с 2005 по 2008 в школе No1304. Из учителей будущей чемпионке запомнилась Екатерина Владимировна, которая часто говорила, что за сорок лет преподавания у нее не было и не будет отличников. По словам Анны, это ее очень закалило. Она всегда училась хорошо, а перейдя в другую школу, все-таки стала отличницей и оставалась ею до тех пор, пока спорт не стал занимать все большее место в ее жизни...", Status = "КA: Нужно ранжировать награды по степени важности" }; context.PersonDescriptions.AddOrUpdate(o => o.Id, staticDesc); context.PersonDescriptions.AddOrUpdate(o => o.Id, new PersonDescription { Id = 2, id_DescriptionType = 2, id_Person = 1, DescriptionText = "Занималась фигурным катанием. Каталась на стадионе “Юных Пионеров”, где ее тренировала Федерченко Любовь Анатольевна.Училась Анна в нескольких московских школах, с 2000 по 2005 в школе No73, а с 2005 по 2008 в школе No1304.К концу учебы стала отличницей и оставалась ею до тех пор, пока спорт не стал занимать все большее место в ее жизни.", Status = "КA: Нужно ранжировать награды по степени важности" }); context.PersonDescriptions.AddOrUpdate(o => o.Id, new PersonDescription { Id = 3, id_DescriptionType = 1, id_Person = 1, DescriptionText = "Лучший скип сборной России. Знаменита не только спортивными достижениями, но и своей привлекательностью.", Status = "КA: Нужно ранжировать награды по степени важности" }); var tizer = new PersonDescription { Id = 4, id_DescriptionType = 1, RequiredStaticDescription = true, IdBlock = 1, id_Person = 1, DescriptionText = "С 2008 в составе международных команд, 3 олимпийских бронзы.С 2011 основной скип сборной России.", Status = "КA: Нужно ранжировать награды по степени важности" }; context.PersonDescriptions.AddOrUpdate(o => o.Id, tizer); context.SaveChanges(); context.PersonDescriptionTizerLinks.AddOrUpdate(new PersonDescriptionTizerLink { IdTizer = tizer.Id, IdStaticDescription = staticDesc.Id }); context.SaveChanges(); context.PersonConnections.AddOrUpdate(o => o.Id, new PersonConnection { Id = 1, id_ConnectionType = 2, id_Person = 1, id_Event = 5, Description = "Артист" }); context.PersonConnections.AddOrUpdate(o => o.Id, new PersonConnection { Id = 2, id_ConnectionType = 3, id_Person = 2, id_Event = 8, Description = "Певец(соло)" }); context.PersonConnections.AddOrUpdate(o => o.Id, new PersonConnection { Id = 3, id_ConnectionType = 2, id_Person = 3, id_Event = 2, Description = "Член команды (основной скип)" }); context.PersonConnections.AddOrUpdate(o => o.Id, new PersonConnection { Id = 4, id_ConnectionType = 2, id_Person = 4, id_Event = 5, Description = "Артист" }); context.PersonConnections.AddOrUpdate(o => o.Id, new PersonConnection { Id = 5, id_ConnectionType = 2, id_Person = 5, id_Event = 5, Description = "Артист (Граф Орлов)" }); context.PersonConnections.AddOrUpdate(o => o.Id, new PersonConnection { Id = 6, id_ConnectionType = 1, id_Person = 5, id_PersonConnectTo = 1, Description = "Подруга" }); context.PersonConnections.AddOrUpdate(o => o.Id, new PersonConnection { Id = 7, id_ConnectionType = 1, id_Person = 5, id_PersonConnectTo = 3, Description = "Подруга" }); context.SaveChanges(); }