Example #1
0
        public static List <AgencyViewModel> ConvertToAgencyViewModelList(this IEnumerable <Agency> Agencies)
        {
            List <AgencyViewModel> AgenciesViewModels = new List <AgencyViewModel>();

            foreach (Agency Agency in Agencies)
            {
                AgenciesViewModels.Add(Agency.ConvertToAgencyViewModel());
            }
            return(AgenciesViewModels);
        }
        public AgencyResponse Create(AgencyViewModel Agency)
        {
            AgencyResponse response = new AgencyResponse();

            try
            {
                Agency addedAgency = unitOfWork.GetAgencyRepository().Create(Agency.ConvertToAgency());
                unitOfWork.Save();

                response.Agency  = addedAgency.ConvertToAgencyViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Agency  = new AgencyViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public AgencyResponse Delete(Guid identifier)
        {
            AgencyResponse response = new AgencyResponse();

            try
            {
                Agency deletedAgency = unitOfWork.GetAgencyRepository().Delete(identifier);

                unitOfWork.Save();

                response.Agency  = deletedAgency.ConvertToAgencyViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Agency  = new AgencyViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }