/// <summary> /// Get Specific Partner. /// </summary> /// <param name="id"></param> /// <returns></returns> public IResult GetPartnerById(string id) { var result = new Result { Operation = Operation.Read, Status = Status.Success }; try { if (!string.IsNullOrEmpty(id)) { var partner = _partnerRepository.GetOne(t => t.PartnerId == ObjectId.Parse(id)); if (partner != null) { var partnerViewModel = new PartnerViewModel(); result.Body = partnerViewModel.MapFromModel(partner); } else { result.Message = PartnerNotification.PartnerNotFound; } } else { result.Status = Status.Fail; result.Message = CommonErrorMessages.NoIdentifierProvided; } } catch (Exception e) { result.Message = e.Message; result.Status = Status.Fail; } return(result); }
/// <summary> /// Insert Partner /// </summary> /// <param name="partnerViewModel"></param> /// <returns></returns> public IResult Create(PartnerViewModel partnerViewModel) { partnerViewModel.PartnerId = null; var result = new Result { Operation = Operation.Create, Status = Status.Success }; try { var partner = new Partner(); partner.MapFromViewModel(partnerViewModel, (ClaimsIdentity)_principal.Identity); _partnerRepository.InsertOne(partner); result.Body = partnerViewModel.MapFromModel(partner); result.Message = PartnerNotification.Created; } catch (Exception e) { result.Message = e.Message; result.Status = Status.Fail; } return(result); }