public ModelBO Create(ModelBO model) { using (var uow = facade.UnitOfWork) { var newModel = uow.ModelRepository.Create(conv.Convert(model)); uow.Complete(); return(conv.Convert(newModel)); } }
protected override Task OnUpdateAsync(IClientSecretIdentity clientSecretIdentity, ClientSecretIdentityModel targetClientSecretIdentityModel) { NullGuard.NotNull(clientSecretIdentity, nameof(clientSecretIdentity)) .NotNull(targetClientSecretIdentityModel, nameof(targetClientSecretIdentityModel)); ClientSecretIdentityModel sourceClientSecretIdentityModel = ModelConverter.Convert <IClientSecretIdentity, ClientSecretIdentityModel>(clientSecretIdentity).With(clientSecretIdentity.ToClaimsIdentity().Claims, DbContext, ModelConverter); targetClientSecretIdentityModel.FriendlyName = sourceClientSecretIdentityModel.FriendlyName; targetClientSecretIdentityModel.ClientId = sourceClientSecretIdentityModel.ClientId; targetClientSecretIdentityModel.ClientSecret = sourceClientSecretIdentityModel.ClientSecret; ClientSecretIdentityClaimModel targetClientSecretIdentityClaimModel; foreach (ClientSecretIdentityClaimModel sourceClientSecretIdentityClaimModel in sourceClientSecretIdentityModel.ClientSecretIdentityClaims) { targetClientSecretIdentityClaimModel = targetClientSecretIdentityModel.ClientSecretIdentityClaims.SingleOrDefault(claim => sourceClientSecretIdentityClaimModel.ClaimIdentifier == claim.ClaimIdentifier); if (targetClientSecretIdentityClaimModel == null) { targetClientSecretIdentityModel.ClientSecretIdentityClaims.Add(sourceClientSecretIdentityClaimModel); continue; } targetClientSecretIdentityClaimModel.ClaimValue = sourceClientSecretIdentityClaimModel.ClaimValue ?? sourceClientSecretIdentityClaimModel.Claim.ClaimValue; } targetClientSecretIdentityClaimModel = targetClientSecretIdentityModel.ClientSecretIdentityClaims.FirstOrDefault(claim => sourceClientSecretIdentityModel.ClientSecretIdentityClaims.Any(c => claim.ClaimIdentifier == c.ClaimIdentifier) == false); while (targetClientSecretIdentityClaimModel != null) { targetClientSecretIdentityModel.ClientSecretIdentityClaims.Remove(targetClientSecretIdentityClaimModel); targetClientSecretIdentityClaimModel = targetClientSecretIdentityModel.ClientSecretIdentityClaims.FirstOrDefault(claim => sourceClientSecretIdentityModel.ClientSecretIdentityClaims.Any(c => claim.ClaimIdentifier == c.ClaimIdentifier) == false); } return(Task.CompletedTask); }
public async Task <SkillActionViewModel[]> GetActionsForSkill(string SkillName) { SkillAction[] actions = await skillsActionService.GetAllForSkill(SkillName); SkillActionViewModel[] result = ModelConverter.Convert <SkillAction, SkillActionViewModel>(actions); return(result); }
// GET: Review/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Model.Review rev; try { rev = lib.GetReview((int)id); } catch (Exception) { return(View()); } if (rev == null) { return(HttpNotFound()); } Model.Restaurant r = lib.GetRestaurant(rev.Subject); if (r == null) { return(HttpNotFound()); } return(View( ModelConverter.Convert(rev, ModelConverter.ConvertLite(r)))); }
public ActionResult Search(string query) { Model.Restaurant[] results = lib.SearchAndParse(query); return(View("Index", ModelConverter.Convert(results))); }
protected override Task OnUpdateAsync(IUserIdentity userIdentity, UserIdentityModel targetUserIdentityModel) { NullGuard.NotNull(userIdentity, nameof(userIdentity)) .NotNull(targetUserIdentityModel, nameof(targetUserIdentityModel)); UserIdentityModel sourceUserIdentityModel = ModelConverter.Convert <IUserIdentity, UserIdentityModel>(userIdentity).With(userIdentity.ToClaimsIdentity().Claims, DbContext, ModelConverter); targetUserIdentityModel.ExternalUserIdentifier = sourceUserIdentityModel.ExternalUserIdentifier; UserIdentityClaimModel targetUserIdentityClaimModel; foreach (UserIdentityClaimModel sourceUserIdentityClaimModel in sourceUserIdentityModel.UserIdentityClaims) { targetUserIdentityClaimModel = targetUserIdentityModel.UserIdentityClaims.SingleOrDefault(claim => sourceUserIdentityClaimModel.ClaimIdentifier == claim.ClaimIdentifier); if (targetUserIdentityClaimModel == null) { targetUserIdentityModel.UserIdentityClaims.Add(sourceUserIdentityClaimModel); continue; } targetUserIdentityClaimModel.ClaimValue = sourceUserIdentityClaimModel.ClaimValue ?? sourceUserIdentityClaimModel.Claim.ClaimValue; } targetUserIdentityClaimModel = targetUserIdentityModel.UserIdentityClaims.FirstOrDefault(claim => sourceUserIdentityModel.UserIdentityClaims.Any(c => claim.ClaimIdentifier == c.ClaimIdentifier) == false); while (targetUserIdentityClaimModel != null) { targetUserIdentityModel.UserIdentityClaims.Remove(targetUserIdentityClaimModel); targetUserIdentityClaimModel = targetUserIdentityModel.UserIdentityClaims.FirstOrDefault(claim => sourceUserIdentityModel.UserIdentityClaims.Any(c => claim.ClaimIdentifier == c.ClaimIdentifier) == false); } return(Task.CompletedTask); }
// GET: Restaurant/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Model.Restaurant r; try { r = lib.GetRestaurant((int)id); } catch (Exception) { return(HttpNotFound()); } if (r == null) { return(HttpNotFound()); } TempData["restId"] = id; return(View(ModelConverter.Convert(r))); }
public ActionResult Edit(EditProjectSourceTypeModel model) { if (!ModelState.IsValid) { return(Redirect(Url.ProjectSourceType_Edit(model.Id))); } ProjectSourceTypeObj obj; if (!model.Id.HasValue) { obj = ModelConverter.Convert(model); obj.Id = ProjectSourceTypeLogic.Create(obj, CurrentUserName); if (obj.Id == -1) { this.AddError("CreatingProjectSourceType", "There was an error creating your ProjectSourceType. If this continues contact support."); return(Redirect(Url.ProjectSourceType_Create())); } } else { obj = ModelConverter.Convert(model); var success = ProjectSourceTypeLogic.Update(obj, CurrentUserName); if (!success) { this.AddError("UpdatingProjectSourceType", "There was an error updating your ProjectSourceType. If this continues contact support."); return(Redirect(Url.ProjectSourceType_Edit(model.Id.Value))); } } return(Redirect(Url.ProjectSourceType_Show(obj.Id.Value))); }
public ActionResult Edit(EditProjectModel model) { if (!ModelState.IsValid) { return(Redirect(Url.Project_Edit(model.Id))); } ProjectObj project; if (!model.Id.HasValue) { project = ModelConverter.Convert(model); project.Id = ProjectLogic.Create(project, CurrentUserName); if (project.Id == -1) { this.AddError("CreatingProject", "There was an error creating your project. If this continues contact support."); return(Redirect(Url.Project_Create())); } } else { project = ModelConverter.Convert(model); var success = ProjectLogic.Update(project, CurrentUserName); if (!success) { this.AddError("UpdatingProject", "There was an error updating your project. If this continues contact support."); return(Redirect(Url.Project_Edit(model.Id.Value))); } } return(Redirect(Url.Project_Show(project.Id.Value))); }
public async Task <SaveResponse> Save(SkillActionViewModel[] Actions) { var skillNames = Actions.Select(action => action.SkillName).Distinct(); SaveRequest <SkillActionViewModel[]> request = new SaveRequest <SkillActionViewModel[]>(); request.ViewModel = Actions; this.ValidateSaveRequest(request); SaveResponse response = new SaveResponse(); if (request.Messages.HasErrors) { response.Messages.AddMessages(request.Messages); return(response); } SkillAction[] actionModels = ModelConverter.Convert <SkillActionViewModel, SkillAction>(Actions); foreach (string skillName in skillNames) { await skillsActionService.DeleteAllForSkill(skillName); } response = await skillsActionService.Save(actionModels); return(response); }
public ActionResult Index() { var model = new ListProjectSourceTypeModel(); var objs = ProjectSourceTypeLogic.GetAll(); model.ProjectSourceTypes = ModelConverter.Convert(objs); return(View(model)); }
public ActionResult Index() { var model = new ListProjectModel(); var objs = ProjectLogic.GetByOwner(CurrentUserName); model.Projects = ModelConverter.Convert(objs); return(View(model)); }
public async Task <FlipViewModel[]> GetFlips() { string userID = await userManager.GetUserIDAsync(HttpContext.User); FlipModel[] model = await flipService.ReadFlips(userID); FlipViewModel[] result = ModelConverter.Convert <FlipModel, FlipViewModel>(model); return(result); }
public ActionResult Edit(Edit viewModel) { // TODO Ensure slug isn't equal to the name of any controllers, or does not start with <controller>/something if (ModelState.IsValid) { string RequestDomain = Globals.GetRequestDomain(); SitePage EditedPage = db.SitePages.SingleOrDefault(x => (x.Id == viewModel.Id) && (x.Site.Domain == RequestDomain)); if (EditedPage == null) { return(HttpNotFound()); } else { // Ensure slug is unique string OldSlug = EditedPage.Slug; string NewSlug = Globals.GetSlug(viewModel.Slug, true); if ((OldSlug != NewSlug) && (db.SitePages.Any(x => (x.Site.Domain == RequestDomain) && (x.Slug == NewSlug)))) { ModelState.AddModelError("SlugAlreadyUsed", "Slug has already been used"); viewModel.GetParents(db); return(View(viewModel)); } else { // View model to domain model ModelConverter.Convert(viewModel, EditedPage); // Assign values for fields not on form EditedPage.DateLastUpdated = DateTime.Now; // Transform values EditedPage.Html = Globals.SaveImagesToDisk(EditedPage.Html); if (EditedPage.ParentId <= 0) { EditedPage.ParentId = null; } EditedPage.Slug = NewSlug; // Save changes db.Entry(EditedPage).State = EntityState.Modified; db.SaveChanges(); // Update cache Caching.ResetPages(); return(RedirectToAction("Index")); } } } else { viewModel.GetParents(db); return(View(viewModel)); } }
public ActionResult Edit(Edit viewModel) { if (ModelState.IsValid) { string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext); SitePage EditedPage = db.SitePages.SingleOrDefault(x => (x.Id == viewModel.Id) && (x.Site.Domain == RequestDomain)); if (EditedPage == null) { return(HttpNotFound()); } else { // Ensure slug is unique string OldSlug = EditedPage.Slug; string NewSlug = Globals.GetSlug(viewModel.Slug, true); if ((OldSlug != NewSlug) && (db.SitePages.Any(x => (x.Site.Domain == RequestDomain) && (x.Slug == NewSlug)))) { ModelState.AddModelError("SlugAlreadyUsed", "Slug has already been used"); viewModel.GetLayouts(); viewModel.GetParents(db); return(View(viewModel)); } else { // View model to domain model ModelConverter.Convert(viewModel, EditedPage); // Assign values for fields not on form EditedPage.DateLastUpdated = DateTime.Now; // Transform values EditedPage.Slug = NewSlug; EditedPage.Html = Globals.SaveImagesToDisk(EditedPage.Html, ControllerContext.HttpContext); // Save changes db.Entry(EditedPage).State = EntityState.Modified; db.SaveChanges(); // Update cache DatabaseCache.RemoveSitePage(ControllerContext.RequestContext.HttpContext, OldSlug); DatabaseCache.RemoveSitePage(ControllerContext.RequestContext.HttpContext, NewSlug); DatabaseCache.ResetNavMenuItems(ControllerContext.RequestContext.HttpContext); return(RedirectToAction("Index")); } } } else { viewModel.GetLayouts(); viewModel.GetParents(db); return(View(viewModel)); } }
public Model LoadModel(string file) { if (models.TryGetValue(file, out Model result)) { return(result); } Model model = ModelConverter.Convert(Loader.LoadModel(file)); models.Add(file, model); return(model); }
public void Convert_WithDestinationAndDynamic_ShouldNotBeNull() { var factory = new Mock<IConverterFactory>(); factory.Setup(x => x.Create<CustomerRequest, Customer>()).Returns(new CustomerRequestCustomerConverter()); var sut = new ModelConverter(factory.Object); var customer = sut.Convert(new CustomerRequest(), new Customer(), new {}); customer.ShouldNotBeNull(); customer.ShouldBeOfType<Customer>(); }
public ActionResult Create(Create viewModel) { // TODO Ensure slug isn't equal to the name of any controllers, or does not start with <controller>/something if (ModelState.IsValid) { string RequestDomain = Globals.GetRequestDomain(); // Ensure slug is unique string Slug = Globals.GetSlug(viewModel.Slug, true); if (db.SitePages.Any(x => (x.Site.Domain == RequestDomain) && (x.Slug == Slug))) { ModelState.AddModelError("SlugAlreadyUsed", "Slug has already been used"); viewModel.GetParents(db); return(View(viewModel)); } else { SitePage NewPage = ModelConverter.Convert <SitePage>(viewModel); // Assign values for fields not on form NewPage.DateAdded = DateTime.Now; NewPage.DateLastUpdated = DateTime.Now; NewPage.SiteId = db.Sites.Single(x => x.Domain == RequestDomain).Id; // Transform values NewPage.Html = Globals.SaveImagesToDisk(NewPage.Html); if (NewPage.ParentId <= 0) { NewPage.ParentId = null; } NewPage.Slug = Globals.GetSlug(NewPage.Slug, true); // Save changes db.SitePages.Add(NewPage); db.SaveChanges(); // Update cache Caching.ResetPages(); return(RedirectToAction("Index")); } } else { viewModel.GetParents(db); return(View(viewModel)); } }
private async Task CreateAsync(IBudgetInfo budgetInfo, BudgetAccountModel budgetAccountModel) { NullGuard.NotNull(budgetInfo, nameof(budgetInfo)) .NotNull(budgetAccountModel, nameof(budgetAccountModel)); BudgetInfoModel budgetInfoModel = ModelConverter.Convert <IBudgetInfo, BudgetInfoModel>(budgetInfo); budgetInfoModel.BudgetAccountIdentifier = budgetAccountModel.BudgetAccountIdentifier; budgetInfoModel.BudgetAccount = budgetAccountModel; EntityEntry <BudgetInfoModel> budgetInfoModelEntityEntry = await Entities.AddAsync(await OnCreateAsync(budgetInfo, budgetInfoModel)); if (budgetAccountModel.BudgetInfos.Contains(budgetInfoModelEntityEntry.Entity) == false) { budgetAccountModel.BudgetInfos.Add(budgetInfoModelEntityEntry.Entity); } }
private async Task CreateAsync(ICreditInfo creditInfo, AccountModel accountModel) { NullGuard.NotNull(creditInfo, nameof(creditInfo)) .NotNull(accountModel, nameof(accountModel)); CreditInfoModel creditInfoModel = ModelConverter.Convert <ICreditInfo, CreditInfoModel>(creditInfo); creditInfoModel.AccountIdentifier = accountModel.AccountIdentifier; creditInfoModel.Account = accountModel; EntityEntry <CreditInfoModel> creditInfoModelEntityEntry = await Entities.AddAsync(await OnCreateAsync(creditInfo, creditInfoModel)); if (accountModel.CreditInfos.Contains(creditInfoModelEntityEntry.Entity) == false) { accountModel.CreditInfos.Add(creditInfoModelEntityEntry.Entity); } }
public ActionResult Create([Bind(Include = "Name,Food")] Models.Restaurant r) { try { if (ModelState.IsValid) { lib.AddRestaurant(ModelConverter.Convert(r)); return(RedirectToAction("Index")); } } catch { return(View()); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public ActionResult Edit(Models.Restaurant r) { try { if (ModelState.IsValid) { lib.EditRestaurant(ModelConverter.Convert(r)); return(RedirectToAction("Index")); } } catch { return(View()); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public ActionResult Edit(Edit viewModel) { if (ModelState.IsValid) { using (var DB = new ApplicationDbContext()) { string RequestDomain = Globals.GetRequestDomain(); SiteBlogPost EditedPost = DB.SiteBlogPosts.SingleOrDefault(x => (x.Id == viewModel.Id) && (x.Site.Domain == RequestDomain)); if (EditedPost == null) { return(HttpNotFound()); } else { // View model to domain model ModelConverter.Convert(viewModel, EditedPost); // Assign values for fields not on form EditedPost.DateLastUpdated = DateTime.Now; // Transform values if (string.IsNullOrWhiteSpace(EditedPost.Slug)) { EditedPost.Slug = EditedPost.Title; } EditedPost.Slug = Globals.GetSlug(EditedPost.Slug, false); // No need to enforce uniqueness, since slug isn't actually used for lookup EditedPost.FullPostText = Globals.SaveImagesToDisk(EditedPost.FullPostText); EditedPost.PreviewText = Globals.SaveImagesToDisk(EditedPost.PreviewText); // Save changes DB.Entry(EditedPost).State = EntityState.Modified; DB.SaveChanges(); // Update cache Caching.ResetBlogPosts(); return(RedirectToAction("Index")); } } } else { return(View(viewModel)); } }
public ActionResult Create(Create viewModel) { if (ModelState.IsValid) { string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext); // Ensure slug is unique string Slug = Globals.GetSlug(viewModel.Slug, true); if (db.SitePages.Any(x => (x.Site.Domain == RequestDomain) && (x.Slug == Slug))) { ModelState.AddModelError("SlugAlreadyUsed", "Slug has already been used"); viewModel.GetLayouts(); viewModel.GetParents(db); return(View(viewModel)); } else { SitePage NewPage = ModelConverter.Convert <SitePage>(viewModel); // Assign values for fields not on form NewPage.DateAdded = DateTime.Now; NewPage.DateLastUpdated = DateTime.Now; NewPage.SiteId = db.Sites.Single(x => x.Domain == RequestDomain).Id; // Transform values NewPage.Slug = Globals.GetSlug(NewPage.Slug, true); NewPage.Html = Globals.SaveImagesToDisk(NewPage.Html, ControllerContext.HttpContext); // Save changes db.SitePages.Add(NewPage); db.SaveChanges(); // Update cache DatabaseCache.ResetNavMenuItems(ControllerContext.RequestContext.HttpContext); return(RedirectToAction("Index")); } } else { viewModel.GetLayouts(); viewModel.GetParents(db); return(View(viewModel)); } }
public ActionResult Create([Bind(Include = "Score, Reviewer, Comment")] Models.Review rev) { try { if (ModelState.IsValid) { rev.SubjectID = (int)TempData["restId"]; lib.AddReview(ModelConverter.Convert(rev)); return(RedirectToAction("Details", "Restaurant", new { id = rev.SubjectID })); } } catch { return(View()); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public void ReceiptPropertyModelConvertTest() { // Arange ReceiptPropertyModel model = new ReceiptPropertyModel() { Key = "Key", Value = "Value" }; Mock <BudgetContext> contextModck = new Mock <BudgetContext>(); ModelConverter converter = new ModelConverter(contextModck.Object); // Act ReceiptProperty result = converter.Convert(model); // Assert Assert.IsNotNull(result); Assert.AreEqual(model.Key, result.Key); Assert.AreEqual(model.Value, result.Value); }
// GET: /Admin/Pages/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext); SitePage Page = db.SitePages.SingleOrDefault(x => (x.Id == id) && (x.Site.Domain == RequestDomain)); if (Page == null) { return(HttpNotFound()); } else { return(View(ModelConverter.Convert <Delete>(Page))); } } }
private ModelImport.ModelImporter InitializeModelImporter(string modelType, ModelConverter modelConverter, string rootDirectory) { switch (modelType) { case "UnityNative": return(new GOModel(rootDirectory)); case "ConversionRequired": modelConverter.Convert(rootDirectory); return(new ConvertedModel(modelConverter.OutputRootDir)); case "ConvertedModel": return(new ConvertedModel(rootDirectory)); case "VolumetricModel": return(new VolumetricModel(rootDirectory)); default: throw Log.ThrowError("Incorrect ModelImporter type declared!", new IOException()); } }
public ActionResult Create(Create viewModel) { if (ModelState.IsValid) { using (var DB = new ApplicationDbContext()) { string RequestDomain = Globals.GetRequestDomain(); // View model to domain model SiteBlogPost NewPost = ModelConverter.Convert <SiteBlogPost>(viewModel); // Assign values for fields not on form NewPost.DateLastUpdated = DateTime.Now; NewPost.DatePosted = DateTime.Now; NewPost.SiteId = DB.Sites.Single(x => x.Domain == RequestDomain).Id; // Transform values if (string.IsNullOrWhiteSpace(viewModel.Slug)) { NewPost.Slug = NewPost.Title; } NewPost.Slug = Globals.GetSlug(NewPost.Slug, false); // No need to enforce uniqueness, since slug isn't actually used for lookup NewPost.FullPostText = Globals.SaveImagesToDisk(NewPost.FullPostText); NewPost.PreviewText = Globals.SaveImagesToDisk(NewPost.PreviewText); // Save changes DB.SiteBlogPosts.Add(NewPost); DB.SaveChanges(); // Update cache Caching.ResetBlogPosts(); return(RedirectToAction("Index")); } } else { return(View(viewModel)); } }
// GET: /Admin/Pages/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { string RequestDomain = Globals.GetRequestDomain(); SitePage Page = db.SitePages.SingleOrDefault(x => (x.Id == id) && (x.Site.Domain == RequestDomain)); if (Page == null) { return(HttpNotFound()); } else { var ViewModel = ModelConverter.Convert <Edit>(Page); ViewModel.GetParents(db); return(View(ViewModel)); } } }
internal async Task <IContact> CreateOrUpdateContactSupplementAsync(IContact contact, string existingExternalIdentifier = null) { NullGuard.NotNull(contact, nameof(contact)); ContactSupplementModel contactSupplementModel = await ReadAsync(contact, existingExternalIdentifier); if (contactSupplementModel == null) { contactSupplementModel = ModelConverter.Convert <IContact, ContactSupplementModel>(contact); await Entities.AddAsync(await OnCreateAsync(contact, contactSupplementModel)); await DbContext.SaveChangesAsync(); return(await ApplyContactSupplementAsync(contact)); } await OnUpdateAsync(contact, contactSupplementModel); await DbContext.SaveChangesAsync(); return(await ApplyContactSupplementAsync(contact)); }
public void Convert_WithNoConveter_ShouldThrowException() { var factory = new Mock<IConverterFactory>(); factory.Setup(x => x.Create<CustomerRequest, Customer>()).Throws<Exception>(); var sut = new ModelConverter(factory.Object); Should.Throw<Exception>( () => { var customer = sut.Convert<CustomerRequest, Customer>(new CustomerRequest()); }); }