public ContributorDetailsReadonly Update(ContributorDetailsEditable model, int objId, EditComponents componentId) { var entity = db.Contributors.FirstOrDefault(x => x.Id == objId); if (entity != null) { switch (componentId) { case EditComponents.Identity: entity.FirstName = model.Identity.FirstName; entity.LastName = model.Identity.LastName; entity.Url = model.Identity.Url; entity.Country = model.Identity.CountriesList.SelectedValues; entity.Age = model.Identity.Age.ItemValue; break; case EditComponents.ProjectRelated: entity.Role = model.ProjectRelated.RoleList.SelectedValues.Value; entity.StartDate = model.ProjectRelated.StartDate.DateValue.Value; entity.Languages = model.ProjectRelated.LanguagesList.SelectedValues; entity.Contributions = model.ProjectRelated.Contributions; break; } db.SaveChanges(); } return(MapContributor_ContributorDetailsModel(entity)); }
public ContributorDetailsEditable ReadEditable(int objId, EditComponents componentId) { var model = db.Contributors.FirstOrDefault(x => x.Id == objId); var result = new ContributorDetailsEditable { Id = model.Id }; if (componentId == EditComponents.Identity) { result.Identity = new ContributorIdentityEditableModel { FirstName = model.FirstName, LastName = model.LastName, Url = model.Url, CountriesList = Lists.AllCountries <string>(false), Age = new BsRangeItem <int?> { ItemValue = model.Age, MinValue = 14, MaxValue = 100, TextValue = model.Age.HasValue ? model.Age.Value.ToString() : string.Empty } }; } else if (componentId == EditComponents.ProjectRelated) { result.ProjectRelated = new ContributorProjectEditableRelatedModel { Contributions = model.Contributions, LanguagesList = Lists.AllLanguages <List <string> >(), StartDate = new BsDateTime() { DateValue = model.StartDate } }; } if (result.Identity != null) { result.Identity.CountriesList.SelectedValues = model.Country; } if (result.ProjectRelated != null) { result.ProjectRelated.LanguagesList.SelectedValues = model.Languages; result.ProjectRelated.RoleList.SelectedValues = model.Role; } return(result); }
public BsJsonResult Update(ContributorDetailsEditable model, int objId, EditComponents componentId) { var msg = string.Empty; var status = BsResponseStatus.Success; var html = string.Empty; var rowsHtml = string.Empty; try { ClearModelState(ModelState, componentId); if (ModelState.IsValid) { var detailsModel = _gridRepository.Update(model, objId, componentId); //simulate exception if (objId == 6) { throw new Exception("This is how an exception message is displayed inside row details"); } switch (componentId) { case EditComponents.Identity: html = this.BsRenderPartialView("Grid/Details/_IdentityReadonly", detailsModel.Identity); break; case EditComponents.ProjectRelated: html = this.BsRenderPartialView("Grid/Details/_ProjectRelatedReadonly", detailsModel.ProjectRelated); break; } var rowModel = _gridRepository.ReadRow(objId); var viewModel = _gridRepository.ToBsGridViewModel(rowModel, true).Wrap <ContributorsViewModel>(x => x.Grid); rowsHtml = this.BsRenderPartialView("Grid/_Grid", viewModel); } } catch (Exception ex) { msg = "<strong>" + Resource.ServerError + "!</strong> " + ex.Message; status = BsResponseStatus.ServerError; } return(new BsJsonResult(new { Html = html, RowsHtml = rowsHtml }, status, msg)); }
public void ClearModelState(ModelStateDictionary ms, EditComponents componentId) { var model = new ContributorDetailsEditable(); switch (componentId) { case EditComponents.Identity: ms.ClearModelState(model.GetPropertyName(m => m.Identity) + "."); break; case EditComponents.ProjectRelated: ms.ClearModelState(model.GetPropertyName(m => m.ProjectRelated) + "."); break; } }
public void ClearModelState(ModelStateDictionary ms, EditComponents componentId) { var model = new ContributorDetailsEditable(); switch (componentId) { case EditComponents.Identity: ms.ClearModelState(model.GetPropertyName(m => m.Identity) + "."); break; case EditComponents.ProjectRelated: ms.ClearModelState(model.GetPropertyName(m => m.ProjectRelated) + "."); break; } }
public BsJsonResult Update(ContributorDetailsEditable model, int objId, EditComponents componentId) { var msg = string.Empty; var status = BsResponseStatus.Success; var html = string.Empty; var rowsHtml = string.Empty; try { ClearModelState(ModelState, componentId); if (ModelState.IsValid) { var detailsModel = _gridRepository.Update(model, objId, componentId); //simulate exception if (objId == 6) { throw new Exception("This is how an exception message is displayed inside row details"); } switch (componentId) { case EditComponents.Identity: html = this.BsRenderPartialView("Grid/Details/_IdentityReadonly", detailsModel.Identity); break; case EditComponents.ProjectRelated: html = this.BsRenderPartialView("Grid/Details/_ProjectRelatedReadonly", detailsModel.ProjectRelated); break; } var rowModel = _gridRepository.ReadRow(objId); var viewModel = _gridRepository.ToBsGridViewModel(rowModel, true).Wrap<ContributorsViewModel>(x => x.Grid); rowsHtml = this.BsRenderPartialView("Grid/_Grid", viewModel); } } catch (Exception ex) { msg = "<strong>" + Resource.ServerError + "!</strong> " + ex.Message; status = BsResponseStatus.ServerError; } return new BsJsonResult(new { Html = html, RowsHtml = rowsHtml }, status, msg); }