protected void ucIDetail_ChildListInstanceRowSaving(object sender, InstanceRowSavingEventArgs e) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType)) { case InstanceTypes.TransactionItem: TransactionFacade facade = new TransactionFacade(uow); TransactionItemDto TransactionItemDto = e.Instance as TransactionItemDto; // Save data IFacadeUpdateResult <TransactionData> result = facade.SaveTransactionItem(CurrentInstance.Id, TransactionItemDto); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh TransactionDto savedCurrentInstance = result.ToDto(new TransactionConverter()); CurrentInstance.TransactionItems = savedCurrentInstance.TransactionItems; } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } break; } } }
public ActionResult Create(int folderId, FormCollection formData) { ReferenceCreateViewModel model = GetCreateViewModel(folderId); UpdateModel(model.Instance, formData); if (ModelState.IsValid) { model.Instance.FolderId = folderId; int selectedTemplateId; if (int.TryParse(formData["SelectedTemplateId"], out selectedTemplateId)) { model.Instance.TemplateId = selectedTemplateId; // Save data IFacadeUpdateResult <ReferenceData> result = Service.SaveReference(model.Instance); if (result.IsSuccessful) { ReferenceDto savedRef = result.ToDto(new ReferenceConverter()); return(RedirectToAction(DetailAction, new { id = savedRef.Id })); } else { ProcUpdateResult(result.ValidationResult, result.Exception); } } else { ModelState.AddModelError("InputError", "Please select Template."); } } return(View(model)); }
protected void ucIDetail_ChildListInstanceRowDeleting(object sender, InstanceRowDeletingEventArgs e) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType)) { case InstanceTypes.OrderItem: OrderFacade facade = new OrderFacade(uow); IFacadeUpdateResult <OrderData> result = facade.DeleteOrderItem(CurrentInstance.Id, e.Instance.Id); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh whole list OrderDto savedParentInstance = result.ToDto(new OrderConverter()); CurrentInstance.OrderItems = savedParentInstance.OrderItems; } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } break; } } }
protected void ucIDetail_ChildListInstanceRowSaving(object sender, InstanceRowSavingEventArgs e) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { DomainFacade facade = new DomainFacade(uow); switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType)) { case InstanceTypes.DomainMainMenu: DomainMainMenuDto itemDto = e.Instance as DomainMainMenuDto; // Save data IFacadeUpdateResult <DomainData> result1 = facade.SaveDomainMainMenu(CurrentInstance.Id, itemDto); e.IsSuccessful = result1.IsSuccessful; if (result1.IsSuccessful) { // Refresh DomainDto savedParentInstance = result1.ToDto(new DomainConverter()); CurrentInstance.DomainMainMenus = savedParentInstance.DomainMainMenus; } else { // Deal with Update result ProcUpdateResult(result1.ValidationResult, result1.Exception); } break; case InstanceTypes.DomainSetupMenu: DomainSetupMenuDto itemDto2 = e.Instance as DomainSetupMenuDto; // Save data IFacadeUpdateResult <DomainData> result2 = facade.SaveDomainSetupMenu(CurrentInstance.Id, itemDto2); e.IsSuccessful = result2.IsSuccessful; if (result2.IsSuccessful) { // Refresh DomainDto savedParentInstance = result2.ToDto(new DomainConverter()); CurrentInstance.DomainSetupMenus = savedParentInstance.DomainSetupMenus; } else { // Deal with Update result ProcUpdateResult(result2.ValidationResult, result2.Exception); } break; } } }
public ActionResult Create(int folderId, FormCollection formData) { DocumentViewModel model = GetModel(null); UpdateModel(model.Instance, formData); if (ModelState.IsValid) { HttpPostedFileBase file = Request.Files[0]; // Deal with file data if (null != file && file.ContentLength > 0) { FileSaveResult fileResult = FileHelper.SaveFile(model.Instance.Title, file); if (fileResult.IsSuccessful) { model.Instance.Title = fileResult.Title; model.Instance.OriginFile = file.FileName; model.Instance.ContentUri = fileResult.FileUri; model.Instance.OriginSource = "Document"; model.Instance.IssuedDate = DateTime.Now; // Save data IFacadeUpdateResult <DocumentData> result = Service.SaveDocument(model.Instance); if (result.IsSuccessful) { DocumentDto savedRef = result.ToDto(new DocumentConverter()); return(RedirectToAction(DetailAction, new { id = savedRef.Id })); } else { ProcUpdateResult(result.ValidationResult, result.Exception); } } else { // TODO: file save exception } } } model.FolderTree = GetCurrentFolderTree(folderId); return(View(model)); }
protected bool SaveInstance() { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { DEntityFacade facade = new DEntityFacade(uow); IFacadeUpdateResult <DEntityData> result = facade.SaveDEntity(CurrentDEntity); if (result.IsSuccessful) { // Refresh Instance CurrentDEntity = result.ToDto <DEntityDto>(new DEntityConverter()); return(true); } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); return(false); } } }
protected void ucIEdit_InstanceSaving(object sender, InstanceSavingEventArgs e) { ProductDto instance = e.Instance as ProductDto; if (instance != null) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { ProductFacade facade = new ProductFacade(uow); IFacadeUpdateResult <ProductData> result = facade.SaveProduct(instance); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh Instance CurrentInstance = result.ToDto <ProductDto>(new ProductConverter()); } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } } } }
public ActionResult Edit(int id, ProductDto instance) { InstanceViewModel model = new InstanceViewModel(InstanceType); if (ModelState.IsValid) { instance.Id = id; IFacadeUpdateResult <ProductData> result = SaveProduct(instance); if (result.IsSuccessful) { ProductDto savedInstance = result.ToDto <ProductDto>(new ProductConverter()); model.Instance = savedInstance; return(EditView(model)); } else { // Deal with Update failed result ProcUpdateResult(result.ValidationResult, result.Exception); } } model.Instance = instance; return(EditView(model)); }
public ActionResult Edit(int id, FormCollection formData) { DocumentViewModel model = GetModel(id); // Collect data from FormCollection UpdateModel(model.Instance, formData); if (ModelState.IsValid) { // Save data IFacadeUpdateResult <DocumentData> result = Service.SaveDocument(model.Instance); if (result.IsSuccessful) { DocumentDto savedRef = result.ToDto(new DocumentConverter()); return(RedirectToAction(DetailAction, new { id = savedRef.Id })); } else { ProcUpdateResult(result.ValidationResult, result.Exception); } } model.FolderTree = GetCurrentFolderTree(); return(View(model)); }
protected void ucIDetail_ChildListInstanceRowDeleting(object sender, InstanceRowDeletingEventArgs e) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType)) { case InstanceTypes.ContactContactMethod: ContactFacade facade = new ContactFacade(uow); IFacadeUpdateResult <ContactData> result = facade.DeleteContactContactMethod(CurrentInstance.Id, e.Instance.Id); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh whole list ContactDto savedCurrentInstance = result.ToDto(new ContactConverter()); CurrentInstance.ContactContactMethods = savedCurrentInstance.ContactContactMethods; // Note: Can't refresh CurrentInstance this way, it will ruin other child list data //ucIDetail.CurrentInstance = savedCurrentInstance; } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } break; case InstanceTypes.ScheduleEvent: ScheduleEventFacade facade2 = new ScheduleEventFacade(uow); // Delete data IFacadeUpdateResult <ScheduleEventData> result2 = facade2.DeleteScheduleEvent(e.Instance.Id); e.IsSuccessful = result2.IsSuccessful; if (result2.IsSuccessful) { // Refresh data in session CurrentInstance.ScheduleEvents = facade2.RetrieveScheduleEventsByContact(CurrentInstance.Id, new ScheduleEventConverter()); } else { // Deal with Update result ProcUpdateResult(result2.ValidationResult, result2.Exception); } break; case InstanceTypes.Activity: ActivityFacade facade3 = new ActivityFacade(uow); // Delete data IFacadeUpdateResult <ActivityData> result3 = facade3.DeleteActivity(e.Instance.Id); e.IsSuccessful = result3.IsSuccessful; if (result3.IsSuccessful) { // Refresh data in session CurrentInstance.Activitys = facade3.RetrieveActivitysByContact(CurrentInstance.Id, new ActivityConverter()); } else { // Deal with Update result ProcUpdateResult(result3.ValidationResult, result3.Exception); } break; case InstanceTypes.Transaction: TransactionFacade facade4 = new TransactionFacade(uow); // Delete data IFacadeUpdateResult <TransactionData> result4 = facade4.DeleteTransaction(e.Instance.Id); e.IsSuccessful = result4.IsSuccessful; if (result4.IsSuccessful) { // Refresh data in session CurrentInstance.Transactions = facade4.RetrieveTransactionsByContact(CurrentInstance.Id, new TransactionConverter()); } else { // Deal with Update result ProcUpdateResult(result4.ValidationResult, result4.Exception); } break; } } }
protected void ucIDetail_ChildListInstanceRowSaving(object sender, InstanceRowSavingEventArgs e) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType)) { case InstanceTypes.ContactContactMethod: ContactFacade facade = new ContactFacade(uow); ContactContactMethodDto contactMethodDto = e.Instance as ContactContactMethodDto; // Save data IFacadeUpdateResult <ContactData> result = facade.SaveContactContactMethod(CurrentInstance.Id, contactMethodDto); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh ContactDto savedCurrentInstance = result.ToDto(new ContactConverter()); CurrentInstance.ContactContactMethods = savedCurrentInstance.ContactContactMethods; // Note: Can't refresh CurrentInstance this way, it will ruin other child list data //ucIDetail.CurrentInstance = savedInstance; } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } break; case InstanceTypes.ScheduleEvent: ScheduleEventFacade facade2 = new ScheduleEventFacade(uow); ScheduleEventDto eventDto = e.Instance as ScheduleEventDto; eventDto.ObjectId = CurrentInstance.Id; eventDto.ObjectTypeId = (int)EventObjectTypes.Contact; // Save data IFacadeUpdateResult <ScheduleEventData> result2 = facade2.SaveScheduleEvent(eventDto); e.IsSuccessful = result2.IsSuccessful; if (result2.IsSuccessful) { // Refresh data in session CurrentInstance.ScheduleEvents = facade2.RetrieveScheduleEventsByContact(CurrentInstance.Id, new ScheduleEventConverter()); } else { // Deal with Update result ProcUpdateResult(result2.ValidationResult, result2.Exception); } break; case InstanceTypes.Activity: ActivityFacade facade3 = new ActivityFacade(uow); ActivityDto activityDto = e.Instance as ActivityDto; activityDto.ContactId = CurrentInstance.Id; activityDto.CustomerId = CurrentInstance.CustomerId; activityDto.EmployeeId = CurrentUserContext.User.MatchId; // Save data IFacadeUpdateResult <ActivityData> result3 = facade3.SaveActivity(activityDto); e.IsSuccessful = result3.IsSuccessful; if (result3.IsSuccessful) { // Refresh data in session CurrentInstance.Activitys = facade3.RetrieveActivitysByContact(CurrentInstance.Id, new ActivityConverter()); } else { // Deal with Update result ProcUpdateResult(result3.ValidationResult, result3.Exception); } break; case InstanceTypes.Transaction: TransactionFacade facade4 = new TransactionFacade(uow); TransactionDto TransactionDto = e.Instance as TransactionDto; TransactionDto.ContactId = CurrentInstance.Id; TransactionDto.CustomerId = CurrentInstance.CustomerId; // Save data IFacadeUpdateResult <TransactionData> result4 = facade4.SaveTransaction(TransactionDto); e.IsSuccessful = result4.IsSuccessful; if (result4.IsSuccessful) { // Refresh data in session CurrentInstance.Transactions = facade4.RetrieveTransactionsByContact(CurrentInstance.Id, new TransactionConverter()); } else { // Deal with Update result ProcUpdateResult(result4.ValidationResult, result4.Exception); } break; } } }
public ActionResult EditGridRow(int referenceId, int jqGridID) { ReferenceInfoDto reference = GetReference(referenceId); GridDto grid = GetGrid(reference, jqGridID); List <GridRowDto> gridRows = reference.GridRows.Where(o => object.Equals(o.GridId, jqGridID)).ToList(); JQGrid gridInstance = new JQGrid(); switch (gridInstance.AjaxCallBackMode) { case AjaxCallBackMode.EditRow: bool isValidEdit = ValidateInput(); if (isValidEdit) { int rowId = Convert.ToInt32(Request.Form[BaseDto.FLD_Id]); GridRowDto row = gridRows.SingleOrDefault(r => r.Id.Equals(rowId)); foreach (GridColumnDto column in grid.Columns) { DucValueDto cell = row.Cells.SingleOrDefault(o => o.DucId.Equals(column.Id)); if (cell != null) { CollectValues(cell, Request.Form, column.ColumnType, reference); } } IFacadeUpdateResult <GridRowData> result = Service.SaveGridRow(row); if (result.IsSuccessful) { GridRowDto savedRow = result.ToDto(new GridRowConverter()); gridRows.Remove(row); gridRows.Add(savedRow); } } break; case AjaxCallBackMode.AddRow: bool isValid = ValidateInput(); if (isValid) { GridRowDto newRow = new GridRowDto(); newRow.ReferenceId = referenceId; newRow.GridId = jqGridID; List <DucValueDto> cells = new List <DucValueDto>(); newRow.Cells = cells; foreach (GridColumnDto column in grid.Columns) { DucValueDto cell = new DucValueDto(); cell.DucId = column.Id; CollectValues(cell, Request.Form, column.ColumnType, reference); cells.Add(cell); } IFacadeUpdateResult <GridRowData> result = Service.SaveGridRow(newRow); if (result.IsSuccessful) { GridRowDto savedRow = result.ToDto(new GridRowConverter()); gridRows.Add(savedRow); } } break; case AjaxCallBackMode.DeleteRow: int deleteRowId = Convert.ToInt32(Request.Form[BaseDto.FLD_Id]); bool isDeleteSuccessful = Service.DeleteGridRow(deleteRowId); gridRows.Remove(gridRows.SingleOrDefault(o => o.Id.Equals(deleteRowId))); break; } return(ConvertToJson(grid, gridRows)); }