コード例 #1
0
        public HttpResponseMessage GetAll()
        {
            try
            {
                var doctorViewModel = new DoctorViewModel();
                var user            = UserMatching.IsUserMatch();
                if (user == null)
                {
                    responseDoctor.UnAuthorized();
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, responseDoctor, contentType));
                }

                SqlParameter[] sqlParameters;
                string         parameter = SQLParameters.GetParameters <DoctorViewModel>(doctorViewModel);
                sqlParameters = SQLParameters.GetSQLParameters <DoctorViewModel>(doctorViewModel, "GetAll").ToArray();
                var doctorsList = unitOfWork.GetRepositoryInstance <DoctorViewModel>().ReadStoredProcedure("Doctor_Detail " + parameter, sqlParameters).ToList();
                responseDoctor.Success((new JavaScriptSerializer()).Serialize(doctorsList));
                return(Request.CreateResponse(HttpStatusCode.Accepted, responseDoctor, contentType));
            }
            catch (Exception exception)
            {
                responseDoctor.Exception(exception.Message);
                return(Request.CreateResponse(HttpStatusCode.Conflict, responseDoctor, contentType));
            }
        }
コード例 #2
0
 public HttpResponseMessage Add([FromBody] SpecializationViewModel specializationViewModel)
 {
     try
     {
         var user = UserMatching.IsUserMatch();
         if (user == null)
         {
             responseSpecialization.UnAuthorized();
             return(Request.CreateResponse(HttpStatusCode.Unauthorized, responseSpecialization, contentType));
         }
         specializationViewModel.CreatedBy         = user.Id;
         specializationViewModel.IsInternalCreated = user.IsInternalUser;
         SqlParameter[] sqlParameters;
         string         parameter = SQLParameters.GetParameters <SpecializationViewModel>(specializationViewModel);
         sqlParameters = SQLParameters.GetSQLParameters <SpecializationViewModel>(specializationViewModel, "GetByName").ToArray();
         var specialization = unitOfWork.GetRepositoryInstance <SpecializationViewModel>().ReadStoredProcedure("Specialization_Detail " + parameter, sqlParameters).ToList();
         if (specialization.Count > 0)
         {
             sqlParameters = SQLParameters.GetSQLParameters <SpecializationViewModel>(specializationViewModel, "GetByName").ToArray();
             responseSpecialization.Failed((new JavaScriptSerializer()).Serialize(specializationViewModel), "Specialization already exist");
             return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, responseSpecialization, contentType));
         }
         else
         {
             sqlParameters = SQLParameters.GetSQLParameters <SpecializationViewModel>(specializationViewModel, "Add").ToArray();
             var result = unitOfWork.GetRepositoryInstance <object>().WriteStoredProcedure("Specialization_Detail " + parameter, sqlParameters);
             if (result >= 1)
             {
                 responseSpecialization.Success((new JavaScriptSerializer()).Serialize(specializationViewModel));
                 return(Request.CreateResponse(HttpStatusCode.Created, responseSpecialization, contentType));
             }
             else
             {
                 responseSpecialization.Failed((new JavaScriptSerializer()).Serialize(specializationViewModel), "Failed to create new specialization, try again");
                 return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, responseSpecialization, contentType));
             }
         }
     }
     catch (Exception exception)
     {
         responseSpecialization.Exception(exception.Message);
         return(Request.CreateResponse(HttpStatusCode.Conflict, responseSpecialization, contentType));
     }
 }