示例#1
0
        public async Task Update(KVRR kvrr)
        {
            try
            {
                if (kvrr == null)
                {
                    throw new InvalidParameterException();
                }

                //delete old image if exist
                if (kvrr.KVRRImage != null)
                {
                    DeleteOldKVRRImage(kvrr.KVRRImagePath);
                }

                kvrr.DateLastUpdated = DateTime.Now;
                kvrr.LastUpdatedBy   = _userManager.CurrentUser();

                //upload new image
                if (kvrr.KVRRImage?.Length > 0)
                {
                    kvrr = UploadKVRRImage(kvrr).Result;
                }

                _unitOfWork.KVRRRepository.Update(kvrr);

                var kpsNew = new List <KVRRPortfolio>();
                // 1 kvrr - multi Portfolio
                //if (kvrr.PortfolioIds != null && kvrr.PortfolioIds.Any())
                //{
                //    foreach (var portfolio in kvrr.PortfolioIds)
                //    {
                //        kpsNew.Add(new KVRRPortfolio
                //        {
                //            KVRRId = kvrr.Id,
                //            PortfolioId = Int32.Parse(portfolio)
                //        });
                //    }
                //}

                // 1 kvrr - 1 Portfolio
                kpsNew.Add(new KVRRPortfolio
                {
                    KVRRId      = kvrr.Id,
                    PortfolioId = Int32.Parse(kvrr.PortfolioId)
                });
                await CreateOrUpdateKVRRPortfolio(kpsNew);

                await _unitOfWork.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        private async Task <KVRR> UploadKVRRImage(KVRR kvrr)
        {
            if (kvrr.KVRRImage.Length > 0)
            {
                var fileName = kvrr.KVRRImage.FileName.Split('\\').Last();
                var filePath = $"{_hostingEnvironment.WebRootPath}{smartFunds.Common.Constants.KVRRImageFolder.Path}{fileName}";

                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await kvrr.KVRRImage.CopyToAsync(stream);
                }
                kvrr.KVRRImagePath = fileName;
            }

            return(kvrr);
        }