Example #1
0
        public async Task Update(Services inputModel)
        {
            try
            {
                var data = await Find_By_Id(inputModel.Id);

                if (inputModel.Price != data.Price)
                {
                    var price = (await _unitOfWork.ServicePriceHistoryRepository.FindBy(c => c.ServiceId == inputModel.Id)).ToList();
                    if (price.Count() > 1) //neu ko phai la lan update dau tien
                    {
                        var lastTimeprice = price.OrderByDescending(c => c.ToDate).FirstOrDefault();
                        lastTimeprice.ToDate = DateTime.Now;
                        await _unitOfWork.ServicePriceHistoryRepository.Update(lastTimeprice);

                        var hisPrice = new ServicePriceHistory();
                        hisPrice.ServiceId = inputModel.Id;
                        hisPrice.Price     = inputModel.Price;
                        hisPrice.FromDate  = DateTime.Now;
                        await _unitOfWork.ServicePriceHistoryRepository.Add(hisPrice);
                    }
                    else
                    {
                        var lastTimeprice = price.FirstOrDefault();
                        lastTimeprice.ToDate = DateTime.Now;
                        await _unitOfWork.ServicePriceHistoryRepository.Update(lastTimeprice);

                        var hisPrice = new ServicePriceHistory();
                        hisPrice.ServiceId = inputModel.Id;
                        hisPrice.Price     = inputModel.Price;
                        hisPrice.FromDate  = DateTime.Now;
                        await _unitOfWork.ServicePriceHistoryRepository.Add(hisPrice);
                    }
                }
                await _unitOfWork.ServicesRepository.Update(inputModel);

                await _unitOfWork.SaveChange();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public async Task Create(Services inputModel)
        {
            try
            {
                await _unitOfWork.ServicesRepository.Add(inputModel);

                var hisPrice = new ServicePriceHistory();
                hisPrice.ServiceId = inputModel.Id;
                hisPrice.Price     = inputModel.Price;
                hisPrice.FromDate  = DateTime.Now;
                await _unitOfWork.ServicePriceHistoryRepository.Add(hisPrice);

                await _unitOfWork.SaveChange();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }