public IEnumerable<IResult> Save()
        {
            this.RemoveAllErrors();
            if (InventoryItem.Id > 0)
            {
                GetIsLockValidRequest getIsLockValidRequest = new GetIsLockValidRequest(ModelNamesEnum.Inventory, this.InventoryItem.Id.ToString());
                yield return getIsLockValidRequest;
                if (getIsLockValidRequest.Error != null)
                {
                    yield return new HandleExceptionResult(getIsLockValidRequest.Error);
                    BusyOff();
                    yield break;
                }
                if (!getIsLockValidRequest.Result)
                {
                    WindowManager.Value.Alert("Unable to continue", "The Record lock has expired.");
                    BusyOff();
                    yield break;
                }
            }

            InventoryAssistantState validatingState;

            BusyOn("Validating Inventory Item...");

            validatingState = InventoryAssistantState.General;
            if (!ValidateGeneral()) {
                this.state = validatingState;
                BusyOff();
                yield break;
            }

            validatingState = InventoryAssistantState.Notes;
            if (AssistantNoteMode == (int)AssistantViewMode.DataEntry)
            {
                if (ValidateNote())
                {
                    NoteSave();
                }
                else
                {
                    NotifyOfPropertyChange(() => ViewModelErrorsString);
                    if (this.State != validatingState)
                        this.State = validatingState;
                    BusyOff();
                    yield break;
                }
            }

            BusyOn("Saving Inventory Item...");

            // Build Save Object
            this.InventoryItem.Notes.Reset(this.Notes);

            //Save Order
            SaveInventoryItemRequest saveInventoryItemRequest = new SaveInventoryItemRequest(this.InventoryItem);
            yield return saveInventoryItemRequest;
            if (saveInventoryItemRequest.Error != null)
            {
                yield return new HandleExceptionResult(saveInventoryItemRequest.Error);
                BusyOff();
                yield break;
            }

            if (this.InventoryItem.Id == null)
                this.InventoryItem.Id = saveInventoryItemRequest.Result;

            GetInventoryItemRequest getInventoryItemRequest = new GetInventoryItemRequest((int)this.InventoryItem.Id);
            yield return getInventoryItemRequest;
            if (getInventoryItemRequest.Error != null)
            {
                yield return new HandleExceptionResult(getInventoryItemRequest.Error);
                BusyOff();
                yield break;
            }
            Events.Value.Publish(new EventModifiedInventory() { InventoryItem = getInventoryItemRequest.Result.Clone() });

            IsDirty = false;
            BusyOff();
            base.Close();
        }
Пример #2
0
        public IEnumerable<IResult> Save()
        {
            if (IsLocked()) {
                BusyOn("Validating Lock...");
                GetIsLockValidRequest getIsLockValidRequest = new GetIsLockValidRequest(ModelNamesEnum.User, this.User.UserId.ToString());
                yield return getIsLockValidRequest;
                if (getIsLockValidRequest.Error != null) {
                    yield return new HandleExceptionResult(getIsLockValidRequest.Error);
                    BusyOff();
                    yield break;
                }
                if (!getIsLockValidRequest.Result) {
                    WindowManager.Value.Alert("Unable to continue", "The Record lock has expired.");
                    BusyOff();
                    yield break;
                }
            }

            BusyOn("Validating User...");
            UserAssistantState validatingState = UserAssistantState.General;
            if (!ValidateGeneral()) {
                this.state = validatingState;
                BusyOff();
                yield break;
            }

            BusyOn("Saving User...");

            //Build Save Object
            //this.User.Role = selectedRole;
            //this.User.RoleId = this.selectedRole.Id;
            //if (!string.IsNullOrWhiteSpace(User.Signature.Signature)) {
            //    if (User.SignatureId == Guid.Empty) {
            //        User.Signature.SignatureId = Guid.NewGuid();
            //        User.SignatureId = User.Signature.SignatureId;
            //    }
            //}

            // If adding user record, hash password that was created
            if (!IsEditMode || ChangePassword)
                User.Password = Security.GetSha2Hash(this.Password.ToString().Trim(), this.User.Username.ToString().Trim());

            // If user record is an admin, create admin key hash
            if (this.User.AdministratorYN)
                this.User.AdministratorKey = Security.GetSha2Hash(User.Username, Session.SessionInfo.Instance.CurrentUser.BaseKey);

            //Save
            SaveUserRequest saveUserRequest = new SaveUserRequest(this.User);
            yield return saveUserRequest;
            if (saveUserRequest.Error != null) {
                yield return new HandleExceptionResult(saveUserRequest.Error);
                BusyOff();
                yield break;
            }

            if (AssistantMode == ViewMode.Add) {
                if (this.User.UserId == null)
                    this.User.UserId = saveUserRequest.Result;
                // Clear All Related Data
                this.User.Signature = new UserSignature();
                // Load any additional data
                this.User.Department = Lib.ListService.Instance.Departments.Where(x => x.DepartmentId == this.User.DepartmentId).SingleOrDefault();
            }

            this.User.IsDirty = false;
            this.User.IsTrackChange = false;
            this.User.OriginalObject = null;
            Events.Value.Publish(new EventModifiedUser() { User = this.User });
            IsDirty = false;
            BusyOff();
            base.Close();
        }
        public IEnumerable<IResult> Save()
        {
            this.RemoveAllErrors();
            if (this.CatalogItem.Pk > 0) {
                var reqLock = new GetIsLockValidRequest(ModelNamesEnum.Catalog, this.CatalogItem.Pk.ToString());
                yield return reqLock;

                if (reqLock.Error != null) {
                    yield return HandleExceptionResult.Display(reqLock.Error);
                    BusyOff();
                    yield break;
                }
                if (!reqLock.Result) {
                    WindowManager.Value.Alert("Unable to continue", "The Record lock has expired.");
                    BusyOff();
                    yield break;
                }
            }

            BusyOn("Validating Catalog Item...");

            if (AssistantCatalogItemPriorityMode == (int)AssistantViewMode.DataEntry) {
                CatalogItemPrioritySave();
            }

            var validatingState = CatalogAssistantState.General;
            if (!ValidateGeneral()) {
                AddError("Form", "Catalog Items Section - Last Save Attempt - Errors exist on form");
                NotifyOfPropertyChange(() => ViewModelErrorsString);
                this.State = validatingState;
                BusyOff();
                yield break;
            }

            NotifyOfPropertyChange(() => ViewModelErrorsString);

            BusyOn("Saving Catalog Item...");

            // Build Domain Object

            //Save CatalogItem
            var reqSave = new SaveCatalogItemRequest(this.CatalogItem);
            yield return reqSave;

            if (reqSave.Error != null) {
                yield return HandleExceptionResult.Display(reqSave.Error);
                BusyOff();
                yield break;
            }

            if (AssistantMode == ViewMode.Add) {
                this.CatalogItem.CatalogId = reqSave.Result;
                // Clear All Related Data to force reloaded on main screen
                // Load any additional data
            }
            this.CatalogItem.IsDirty = false;
            this.CatalogItem.IsTrackChange = false;
            this.CatalogItem.OriginalObject = null;
            Events.Value.Publish(new EventLoadCatalogItems());
            IsDirty = false;
            BusyOff();
            base.Close();
        }