public void Delete(DepreciationViewModel model) { var entity = model.ToEntity(); this._DepreciationRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
public async Task <IActionResult> Edit(int id, DepreciationViewModel obj) { string userId = User.Identity.Name; if (ModelState.IsValid) { await _depreciationViewModelService.UpdateDepreciationAsync(obj, userId); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task <IActionResult> Insert(DepreciationViewModel item) { string userId = User.Identity.Name; if (ModelState.IsValid) { await _depreciationViewModelService.AddDepreciationAsync(item, userId); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task UpdateDepreciationAsync(DepreciationViewModel depreciationVM, string userId) { _logger.LogInformation("UpdateDepreciationAsync called."); var depreciation = new Depreciation() { Id = depreciationVM.Id, Name = depreciationVM.Name, Months = depreciationVM.Months, UpdatedAt = DateTime.Now, UpdatedBy = userId }; await _depreciationRepository.UpdateAsync(depreciation); }
public void ThrowExceptionIfExist(DepreciationViewModel model) { //ConditionFilter<Depreciation, long> condition = new ConditionFilter<Depreciation, long> //{ // Query = (entity => // entity.Name == model.Name && // entity.Id != model.Id) //}; //var existEntity = this._DepreciationRepository.Get(condition).FirstOrDefault(); //if (existEntity != null) // throw new ItemAlreadyExistException(); }
public async Task <DepreciationViewModel> GetDepreciationAsync(int id) { _logger.LogInformation("GetDepreciationAsync called."); var depreciation = await _depreciationRepository.GetByIdAsync(id); DepreciationViewModel depreciationViewModel = new DepreciationViewModel() { Id = depreciation.Id, Name = depreciation.Name, Months = depreciation.Months }; return(depreciationViewModel); }
public DepreciationViewModel Add(DepreciationViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._DepreciationRepository.Add(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public async Task <IActionResult> Delete(int id, DepreciationViewModel item) { if (item == null) { return(RedirectToAction(nameof(Index))); } try { await _depreciationViewModelService.DeleteDepreciationAsync(item.Id); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public IEnumerable <DepreciationViewModel> GetAllDepreciation() { _logger.LogInformation("GetAllDepreciation called."); var depreciations = _repository.ListAll(); var depreciationList = new List <DepreciationViewModel>(); foreach (var depreciation in depreciations) { var depView = new DepreciationViewModel() { Id = depreciation.Id, Name = depreciation.Name, Months = depreciation.Months }; depreciationList.Add(depView); } return(depreciationList); }
public DepreciationViewModel Update(DepreciationViewModel model) { this.ThrowExceptionIfExist(model); var entity = this._DepreciationRepository.Get(model.Id); //entity.LocationId = model.LocationId; //entity.AccountChartId = model.AccountChartId; entity = this._DepreciationRepository.Update(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public DepreciationChildWindow(DepreciationViewModel viewModel) { InitializeComponent(); _viewModel = viewModel; DataContext = _viewModel; }
public IList <DepreciationViewModel> Add(IEnumerable <DepreciationViewModel> collection) { Language lang = this._languageService.CurrentLanguage; IList <Asset> FailedToUpdate = new List <Asset>(); IList <Asset> assetsToUpdate = new List <Asset>(); List <Depreciation> depreciations = new List <Depreciation>(); IList <DepreciationViewModel> DepreciationViewModels = collection.ToList(); DateTime now = DateTime.Now; //DateTime depreciationDate = DateTime.Now; foreach (var model in collection) { Asset asset = this._AssetsRepository.Get(model.AssetId); DateTime startDepreciationDate; if (asset.StartDepreciationDate.HasValue) { startDepreciationDate = asset.StartDepreciationDate.Value; } else { startDepreciationDate = asset.PurchaseDate.Value; } switch (asset.DepreciationRate.DepreciationRateCode) { case DepreciationRateCodeEnum.Day: { if (asset.LastDepreciationDate == null) { model.NextDepreciationDate = startDepreciationDate; } else { model.NextDepreciationDate = asset.LastDepreciationDate.Value.AddDays(1); } } break; case DepreciationRateCodeEnum.Month: { if (asset.LastDepreciationDate == null) { model.NextDepreciationDate = startDepreciationDate.AddMonths(1); } else { model.NextDepreciationDate = asset.LastDepreciationDate.Value.AddMonths(1); } } break; case DepreciationRateCodeEnum.Year: { if (asset.LastDepreciationDate == null) { model.NextDepreciationDate = startDepreciationDate.AddYears(1); } else { model.NextDepreciationDate = asset.LastDepreciationDate.Value.AddYears(1); } } break; default: break; } //switch (asset.DepreciationRate.DepreciationRateCode) //{ // case MersalAccountingService.Common.Enums.DepreciationRateCodeEnum.Day: // depreciationDate = DateTime.Now.AddDays(1); // break; // case MersalAccountingService.Common.Enums.DepreciationRateCodeEnum.Month: // depreciationDate = DateTime.Now.AddMonths(1); // break; // case MersalAccountingService.Common.Enums.DepreciationRateCodeEnum.Year: // depreciationDate = DateTime.Now.AddYears(1); // break; // default: // break; //} if (model.NextDepreciationDate > now) //if (asset.LastDepreciationDate <= depreciationDate) { FailedToUpdate.Add(asset); DepreciationViewModel depreciationViewModel = DepreciationViewModels.FirstOrDefault(x => x.AssetId == asset.Id); DepreciationViewModels.Remove(depreciationViewModel); //model.AccountChart = asset.AccountChart.ToModel(); BrandViewModel brand = asset.Brand.ChildTranslatedBrands.FirstOrDefault(c => c.Language == lang).ToModel(); DepreciationRateViewModel depreciation = asset.DepreciationRate.ToModel(); if (lang == Language.Arabic) { model.BrandName = brand.NameAr; model.DepreciationRateName = depreciation.NameAr; } else if (lang == Language.English) { model.BrandName = brand.NameEn; model.DepreciationRateName = depreciation.NameEn; } model.CurrentValue = asset.CurrentValue; model.Successed = false; } else { asset.CurrentValue -= asset.DepreciationValue; if (asset.CurrentValue < 0) { asset.CurrentValue = 0; } asset.LastDepreciationDate = now; assetsToUpdate.Add(asset); depreciations.Add(new Depreciation { AssetId = asset.Id }); //model.AccountChart = asset.AccountChart.ToModel(); BrandViewModel brand = asset.Brand.ChildTranslatedBrands.FirstOrDefault(c => c.Language == lang).ToModel(); DepreciationRateViewModel depreciation = asset.DepreciationRate.ToModel(); if (lang == Language.Arabic) { model.BrandName = brand.NameAr; model.DepreciationRateName = depreciation.NameAr; } else if (lang == Language.English) { model.BrandName = brand.NameEn; model.DepreciationRateName = depreciation.NameEn; } model.CurrentValue = asset.CurrentValue; model.Successed = true; switch (asset.DepreciationRate.DepreciationRateCode) { case DepreciationRateCodeEnum.Day: { model.NextDepreciationDate = asset.LastDepreciationDate.Value.AddDays(1); } break; case DepreciationRateCodeEnum.Month: { model.NextDepreciationDate = asset.LastDepreciationDate.Value.AddMonths(1); } break; case DepreciationRateCodeEnum.Year: { model.NextDepreciationDate = asset.LastDepreciationDate.Value.AddYears(1); } break; default: break; } } //if (asset.CurrentValue <= 0) //{ //} this.ThrowExceptionIfExist(model); } var entityCollection = DepreciationViewModels.Select(model => model.ToEntity()); entityCollection = this._DepreciationRepository.Add(depreciations).ToList(); this._AssetsRepository.Update(assetsToUpdate); #region Commit Changes this._unitOfWork.Commit(); #endregion //var modelCollection = entityCollection.Select(entity => entity.ToModel()).ToList(); return(collection.ToList()); }