public async Task <ImportExportHistory> CreateAsync(ImportExportHistory obj, bool saveChange = true)
        {
            var item = new ImportExportHistory
            {
                Id               = Guid.NewGuid().ToString(),
                Creator          = "Tam",
                CreationDate     = DateTime.Now.ToString(),
                FkStore          = "1",
                IsDeleted        = (int)IsDelete.Normal,
                FkItemOrMaterial = obj.FkItemOrMaterial,
                IsImported       = obj.IsImported,
                Quantity         = obj.Quantity,
                Reason           = obj.Reason
            };

            _DbContext.ImportExportHistory.Add(item);

            try
            {
                if (saveChange)
                {
                    await _DbContext.SaveChangesAsync().ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(item);
        }
        public async Task <ImportExportHistory> UpdateAsync(ImportExportHistory obj, bool saveChange = true)
        {
            var item = await _DbContext.ImportExportHistory.FirstOrDefaultAsync(h => h.Id == obj.Id);

            try
            {
                if (saveChange)
                {
                    await _DbContext.SaveChangesAsync().ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(item);
        }
示例#3
0
        private async void OnSave(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var dataContext  = Helper.GetDataContext();
                var itemLogic    = new ItemLogic(dataContext);
                var historyLogic = new ImportExportHistoryLogic(dataContext);

                var param = new NavigationParameters();
                //Update Số lượng Item và Material

                if (QuantityBindProp > 0)
                {
                    await itemLogic.ModifyQuantityAsync(Item.Id, QuantityBindProp, false);

                    var history = new ImportExportHistory
                    {
                        FkItemOrMaterial = Item.Id,
                        IsImported       = 1,
                        Quantity         = QuantityBindProp,
                        Reason           = IsSelectingOtherReason == true ? OtherReasonBindProp : _reason
                    };

                    var his = await historyLogic.CreateAsync(history, false);

                    var visualHistory = new VisualHistoryModel
                    {
                        Quantity     = history.Quantity,
                        Reason       = history.Reason,
                        CreationDate = his.CreationDate,
                        Item         = Item.ItemName
                    };
                    await dataContext.SaveChangesAsync();

                    Item.CurrentQuantity += QuantityBindProp;

                    param.Add(Keys.HISTORY, visualHistory);
                    await NavigationService.GoBackAsync(param);
                }
                else
                {
                    await PageDialogService.DisplayAlertAsync("Cảnh báo", "Bạn chưa nhập số lượng giảm!", "OK");
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }