public async Task <ShareholderDto> GetID(int ID) { ShareholderDto shareholderDto = new ShareholderDto(); Shareholder shareholder = new Shareholder(); try { int CacheTimeOutInHours = this.configuration.GetValue <int>("MemoryCache:CacheTimeOutInHours"); if (CacheTimeOutInHours <= 0) { CacheTimeOutInHours = 1; } IEnumerable <Shareholder> shareholders = new List <Shareholder>(); shareholders = cache.Get <IEnumerable <Shareholder> >(string.Format("{0}", CacheEnum.SHAREHOLDERS.ToString())); if (shareholders == null || !shareholders.Any()) { shareholder = await this.shareholderRepository.GetByID(ID); return(this.mapper.Map <ShareholderDto>(shareholder)); } shareholderDto = this.mapper.Map <ShareholderDto>(shareholders.FirstOrDefault(x => x.ShareholderID == ID)); } catch (Exception er) { logger.LogError(string.Format("{0}===================={1}====================\n", DateTime.Now.ToString(), er.ToString())); } return(shareholderDto); }
public async Task <IActionResult> Put(int id, [FromBody] ShareholderDto shareholder) { if (ModelState.IsValid) { return(Ok(await this.shareholderService.UpdateShareholder(id, shareholder))); } return(BadRequest("Invalid Data")); }
public void PostShareholder([FromBody] ShareholderDto shareholderDto) { Shareholder com = new Shareholder(); com.Id = shareholderDto.Id; com.TotalShares = shareholderDto.TotalShares; com.Status = shareholderDto.Status; com.UserId = shareholderDto.UserId; com.ShareholderTypeId = shareholderDto.ShareholderTypeId; com.CompanyId = shareholderDto.CompanyId; stocky.Shareholder.Add(com); stocky.SaveChanges(); }
public void PutShareholder(String id, [FromBody] ShareholderDto shareholderDto) { // stocky.Company.Update(id, com); Shareholder com = stocky.Shareholder.Where(e => e.Id == shareholderDto.Id).Single <Shareholder>(); com.Id = shareholderDto.Id; com.TotalShares = shareholderDto.TotalShares; com.Status = shareholderDto.Status; com.UserId = shareholderDto.UserId; com.ShareholderTypeId = shareholderDto.ShareholderTypeId; com.CompanyId = shareholderDto.CompanyId; stocky.Entry(com).State = Microsoft.EntityFrameworkCore.EntityState.Modified; stocky.SaveChanges(); }
public dynamic GetShareholder(String userID, String shareholder_Type, String companyID) { List <Shareholder> shareholder; List <ShareholderDto> shareholderDtos = new List <ShareholderDto>(); if (userID != null && shareholder_Type == null && companyID == null) { shareholder = stocky.Shareholder.Where(e => e.UserId == userID).ToList(); } else if (userID == null && shareholder_Type != null && companyID == null) { shareholder = stocky.Shareholder.Where(e => e.ShareholderTypeId == shareholder_Type).ToList(); } else if (userID == null && shareholder_Type == null && companyID != null) { shareholder = stocky.Shareholder.Where(e => e.CompanyId == companyID).ToList(); } else if (userID != null && shareholder_Type != null && companyID == null) { shareholder = stocky.Shareholder.Where(e => e.UserId == userID && e.ShareholderTypeId == shareholder_Type).ToList(); } else if (userID != null && shareholder_Type == null && companyID != null) { shareholder = stocky.Shareholder.Where(e => e.UserId == userID && e.CompanyId == companyID).ToList(); } else if (userID == null && shareholder_Type != null && companyID != null) { shareholder = stocky.Shareholder.Where(e => e.ShareholderTypeId == shareholder_Type && e.CompanyId == companyID).ToList(); } else if (userID == null && shareholder_Type == null && companyID == null) { shareholder = stocky.Shareholder.ToList(); } else { shareholder = stocky.Shareholder.Where(e => e.UserId == userID && e.ShareholderTypeId == shareholder_Type && e.CompanyId == companyID).ToList(); } foreach (Shareholder com in shareholder) { ShareholderDto dto = new ShareholderDto( com.Id, com.TotalShares, com.Status, com.UserId, com.ShareholderTypeId, com.CompanyId); shareholderDtos.Add(dto); } return(shareholderDtos); }
public async Task <ShareholderDto> UpdateShareholder(int id, ShareholderDto shareholderDto) { try { Shareholder shareholder = new Shareholder(); shareholder = this.mapper.Map <Shareholder>(shareholderDto); await this.shareholderAddressRepository.Update(shareholder.ShareholderAddress); await this.shareholderBankRepository.Update(shareholder.ShareholderBank); await shareholderRepository.Update(shareholder); await shareholderRepository.Save(); cache.Remove(string.Format("{0}", CacheEnum.SHAREHOLDERS.ToString())); shareholderDto = this.mapper.Map <ShareholderDto>(shareholder); } catch (Exception er) { logger.LogError(string.Format("{0}===================={1}====================\n", DateTime.Now.ToString(), er.ToString())); } return(shareholderDto); }
public async Task <ShareholderDto> CreateShareholder(ShareholderDto shareholderDto) { Shareholder shareholder = new Shareholder(); ShareholderAddress shareholderAddress = new ShareholderAddress(); ShareholderAddressDto shareholderAddressDto = new ShareholderAddressDto(); ShareholderBank shareholderBank = new ShareholderBank(); ShareholderBankDto shareholderBankDto = new ShareholderBankDto(); IEnumerable <Shareholder> checkShareholder = new List <Shareholder>(); string base64Image = string.Empty; try { if (shareholder.Company) { checkShareholder = await this.shareholderRepository.Find(x => x.GSM01 == shareholderDto.GSM01 && x.CompanyName.ToLower().Trim() == shareholderDto.CompanyName.ToLower().Trim()); } else { checkShareholder = await this.shareholderRepository.Find(x => x.GSM01 == shareholderDto.GSM01 && x.Lastname.ToLower().Trim() == shareholderDto.Lastname.ToLower().Trim() && x.Firstname.ToLower().Trim() == shareholderDto.Firstname.ToLower().Trim() && x.Middlename.ToLower().Trim() == shareholderDto.Middlename.ToLower().Trim()); } if (checkShareholder == null || !checkShareholder.Any()) { //if (!string.IsNullOrEmpty(shareholderDto.ImageString)) //{ // string url = this.cache.Get<string>(shareholderDto.ImageString); // if (!string.IsNullOrEmpty(url)) // { // base64Image = fileManager.ConvertImageToByte_FromByteToBase64String(url); // if (!string.IsNullOrEmpty(base64Image)) // { // shareholderDto.ImageString = base64Image; // this.fileManager.DeleteFIle(url); // } // } //} //shareholderAddressDto = shareholderDto.ShareholderAddress; //shareholderAddressDto.CapturedDate = DateTime.Now; //shareholderDto.ShareholderAddress = new ShareholderAddressDto(); //shareholderBankDto = shareholderDto.ShareholderBank; //shareholderBankDto.CapturedDate = DateTime.Now; //shareholderDto.ShareholderBank = new ShareholderBankDto(); //shareholderAddress = this.mapper.Map<ShareholderAddress>(shareholderAddressDto); //shareholderBank = this.mapper.Map<ShareholderBank>(shareholderBankDto); shareholder = this.mapper.Map <Shareholder>(shareholderDto); shareholder.ShareholderAddress.CapturedDate = DateTime.Now; shareholder.ShareholderBank.CapturedDate = DateTime.Now; shareholderAddress = await this.shareholderAddressRepository.Create(shareholder.ShareholderAddress); shareholderBank = await this.shareholderBankRepository.Create(shareholder.ShareholderBank); shareholder = await shareholderRepository.Create(shareholder); await shareholderRepository.Save(); shareholder.ShareholderAddressID = shareholderAddress.ShareholderAddressID; shareholderAddress.ShareholderID = shareholder.ShareholderID; shareholder.ShareholderBankID = shareholderBank.ShareholderBankID; shareholderBank.ShareholderID = shareholder.ShareholderID; await shareholderRepository.Update(shareholder); await this.shareholderAddressRepository.Update(shareholder.ShareholderAddress); await this.shareholderBankRepository.Update(shareholder.ShareholderBank); await shareholderRepository.Save(); cache.Remove(string.Format("{0}", CacheEnum.SHAREHOLDERS.ToString())); } } catch (Exception er) { logger.LogError(string.Format("{0}===================={1}====================\n", DateTime.Now.ToString(), er.ToString())); } return(this.mapper.Map <ShareholderDto>(shareholder)); }