public HttpResponseMessage GetCustomers() { Logger.Debug("Inside EM Controller- GetCustomers"); Logger.Debug("No Request Body"); EMCustomers lResponse = new EMCustomers(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IEMServer.ValidateUser(SessionID)) { System.Guid OrganizationGUID = _IEMServer.GetOrganizationGUID(SessionID); if (OrganizationGUID != Guid.Empty) { lResponse = _IEMServer.GetCustomers(new Guid(OrganizationGUID.ToString())); if (lResponse != null) { Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); return Request.CreateResponse(HttpStatusCode.OK, lResponse); } else { ErrorResponse error = new ErrorResponse(); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; return Request.CreateResponse(HttpStatusCode.InternalServerError, error); } } else { ErrorResponse error = new ErrorResponse(); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; return Request.CreateResponse(HttpStatusCode.InternalServerError, error); } } else { return Request.CreateResponse(HttpStatusCode.Forbidden, lResponse); } } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } } catch (Exception ex) { Logger.Error(ex.Message); ErrorResponse error = new ErrorResponse(); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; return Request.CreateResponse(HttpStatusCode.InternalServerError, error); } }
public HttpResponseMessage Login([FromBody]LoginRequest pLoginRequest) { Logger.Debug("Inside UMController- Login"); //Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(pLoginRequest)); LoginResponse LoginResponse = new LoginResponse(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); //error.ErrorCode = HttpStatusCode.OK; //// error.ErrorMessage = "Unable to Get User Details"; //error.ErrorMessage = "Checking Prabhu."; //response.Add("ErrorResponse", error); //return Request.CreateResponse(HttpStatusCode.OK, response); try { //int b = 0; //int a = 1 / b; //pLoginRequest.Cred.UserName = Encoding.UTF8.GetString(Convert.FromBase64String(pLoginRequest.Cred.UserName)); //pLoginRequest.Cred.Password = Encoding.UTF8.GetString(Convert.FromBase64String(pLoginRequest.Cred.Password)); string[] lCred = Encoding.UTF8.GetString(Convert.FromBase64String(pLoginRequest.Cred)).Split(':'); if (lCred.Count() > 1) { pLoginRequest.UserName = lCred[0]; pLoginRequest.Password = lCred[1]; } pLoginRequest.LoginType = eLoginType.DeviceLogin; LoginResponse = _IUMServer.Login(pLoginRequest); if (LoginResponse != null) { Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(LoginResponse)); response.Add("LoginResponse", LoginResponse); return Request.CreateResponse(HttpStatusCode.OK, response); } else { error.ErrorCode = HttpStatusCode.PreconditionFailed; // error.ErrorMessage = "Unable to Get User Details"; error.ErrorMessage = "Invalid Username and Password." + pLoginRequest.UserName + ":" + pLoginRequest.Password; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.PreconditionFailed, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage Login([FromBody]LoginRequest pLoginRequest) { log4net.Config.XmlConfigurator.Configure(); ILog log = LogManager.GetLogger("Inside Login Controller- Login"); LoginResponse loginResponse = new LoginResponse(); try { loginResponse = _ILoginServer.Login(pLoginRequest); return Request.CreateResponse(HttpStatusCode.OK, loginResponse); } catch (Exception ex) { log.Debug(ex.Message); ErrorResponse error = new ErrorResponse(); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; return Request.CreateResponse(HttpStatusCode.InternalServerError, error); } }
public HttpResponseMessage GetList() { Logger.Debug("Inside JM Controller- GetList "); Logger.Debug("Request: No Request Structure."); ErrorResponse error = new ErrorResponse(); ConfigurationResponse lresponse = new ConfigurationResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { { error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "List is not available"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage PostHeartBeat([FromBody]HeartBeatRequest HeartBeatRequest) { Logger.Debug("Inside UM Controller- PostHeartBeat"); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(HeartBeatRequest)); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IUMServer.ValidateUser(SessionID)) { System.Guid UserGUID = _IUMServer.GetUserGUID(SessionID); if (_IUMServer.PostHeartBeat(HeartBeatRequest, UserGUID) > 0) { Logger.Debug("Response: No response In Body,Process is Success"); return Request.CreateResponse(HttpStatusCode.OK); } else { error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to insert PostHeartBeat"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage GetRouteUsers([FromBody]GetRouteUserRequest GetRouteUserRequest) { Logger.Debug("Inside UM Controller- GetRouteUsers "); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(GetRouteUserRequest)); GetRouteUserResponse lResponse = new GetRouteUserResponse(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IUMServer.ValidateUser(SessionID)) { lResponse = _IUMServer.GetRouteUsers(GetRouteUserRequest); if (lResponse != null) { Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); return Request.CreateResponse(HttpStatusCode.OK, lResponse); } else { error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage ForgotPWD([FromBody]ForgotPasswordRequest pForgotPassword) { Logger.Debug("Inside UMController- Forgot Password"); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(pForgotPassword)); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { int result = _IUMServer.ForgotPassword(pForgotPassword); if (result == 1) { Logger.Debug("Response: No response In Body,Process is Success"); return Request.CreateResponse(HttpStatusCode.OK); } else if (result == 401) { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Provided Email ID is not match with any User"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to send mail"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage InsertPO([FromBody]MobilePO MobilePO) { Logger.Debug("Inside JM Controller- InsertPO"); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(MobilePO)); MobilePO lResponse = new MobilePO(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { int result = _IJMServer.InsertPO(MobilePO); if (result > 0) { Logger.Debug("Response: No response In Body,Process is Success"); return Request.CreateResponse(HttpStatusCode.OK); } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage GetCustomers(Customer pcustomer) { log4net.Config.XmlConfigurator.Configure(); ILog log = LogManager.GetLogger("Inside UM Controller- GetCustomers"); UMResponseCustomer lResponse = new UMResponseCustomer(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { // SessionID = Request.Headers.LastOrDefault().Value.First(); SessionID = pcustomer.SessionGUID; Guid lOrganizationGuid = _IUMServer.GetOrganizationGUIDBySessionID(SessionID); if (lOrganizationGuid != null && lOrganizationGuid != Guid.Empty) { lResponse.Customers = _IUMServer.GetCustomers(lOrganizationGuid); Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); response.Add("CustomersResponse", lResponse); return Request.CreateResponse(HttpStatusCode.OK, response); } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { log.Debug(ex.Message); error = new ErrorResponse(); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; return Request.CreateResponse(HttpStatusCode.InternalServerError, error); } }
public HttpResponseMessage CreateJobForCustomerStop([FromBody]CreateJobForCustomerStopRequest jobRequest) { //StringBuilder lretString = new StringBuilder(); Logger.Debug("Inside JM Controller- CreateJobForCustomerStop"); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(jobRequest)); MobileJob lResponse = new MobileJob(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); int errorCode = 0; try { string SessionID = Guid.Empty.ToString(); // lretString.Append("[1: Sesseion Initialized]"); if (Request.Headers != null) { // lretString.Append(" [2: Header is not null: Actual Header is :]" + Request.Headers.ToString() + ""); //SessionID = Request.Headers.LastOrDefault().Value.First(); SessionID = jobRequest.SessionGUID; //lretString.Append(" [3: Sesseion ID" + SessionID + "]"); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { //lretString.Append(" [4: Valid Sesseion ID" + SessionID + "]"); Guid UserGUID = _IJMServer.GetUserGUID(SessionID); //lretString.Append(" [4.1: Valid User ID" + UserGUID + "]"); lResponse = _IJMServer.CreateJobForCustomerStop(jobRequest, UserGUID, ref errorCode); //lretString.Append(" [4.2: Error Code" + errorCode + "]"); if (lResponse != null) { //error.ErrorMessage = "Success. retStr : " + lretString.ToString(); // response.Add("ErrorResponse", error); response.Add("Jobs", lResponse); Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); return Request.CreateResponse(HttpStatusCode.OK, response); } else { error.ErrorCode = HttpStatusCode.BadRequest; if (errorCode == 1) error.ErrorMessage = "Failure: Managers doesn't belong to this store"; else error.ErrorMessage = "Failure: Invalid Store ID"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } else { //lretString.Append(" [5: Invalid Sesseion ID" + SessionID + "]"); //error.ErrorMessage = "Session has expired, please login again. retStr : " + lretString.ToString(); error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { // lretString.Append(" [6: Header is null]"); //error.ErrorMessage = "Failure " + lretString.ToString(); error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); // lretString.Append(" [7: Error " + ex.Message + "]"); //error.ErrorMessage = "Failure " + lretString.ToString(); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage GetJobs([FromBody]string UserGUID) { Logger.Debug("Inside JM Controller- GetJobs"); if (UserGUID != null) Logger.Debug("UserGUID: " + UserGUID.ToString()); JMResponse jmResponse = new JMResponse(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { if (!string.IsNullOrEmpty(UserGUID)) { jmResponse = _IJMServer.GetJobs(new Guid(UserGUID)); } else { jmResponse = _IJMServer.GetJobs(_IJMServer.GetUserGUID(SessionID)); } if (jmResponse != null) { //Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(jmResponse)); return Request.CreateResponse(HttpStatusCode.OK, jmResponse); } else { error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to get job Information"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage GetTerritoryRegion() { Logger.Debug("Inside UM Controller- GetTerritoryRegion"); TerritoryRegion lResponse = new TerritoryRegion(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IUMServer.ValidateUser(SessionID)) { Guid UserGUID = _IUMServer.GetUserGUID(SessionID); lResponse = _IUMServer.GetTerritoryRegion(UserGUID); if (lResponse != null) { Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); response.Add("TerritoryRegion", lResponse); return Request.CreateResponse(HttpStatusCode.OK, response); } else { error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to get Region and Territory Details"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, lResponse); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage UploadJobs([FromBody]UploadJobRequestNew UploadJobRequest) { Logger.Debug("Inside JM Controller- UploadJobs "); Logger.Debug("Inside JM Controller- " + UploadJobRequest.ActualStartTime); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(UploadJobRequest)); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { // SessionID = Request.Headers.LastOrDefault().Value.First(); SessionID = UploadJobRequest.SessionGUID; Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { Guid UserGUID = _IJMServer.GetUserGUID(SessionID); int result = _IJMServer.UploadJobs(UploadJobRequest, UserGUID); if (result > 0) { Logger.Debug("Response: No response In Body,Process is Success"); return Request.CreateResponse(HttpStatusCode.OK); } else if (result == -1) { Logger.Debug("Response: Unable to generate PDF"); return Request.CreateResponse(HttpStatusCode.OK); } else { error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to Upload Jobs"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage UpdateJobStatus([FromBody]UpdateJobStatusRequest JMOwnJobRequest) { Logger.Debug("Inside JM Controller- UpdateJobStatus "); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(JMOwnJobRequest)); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { Guid UserGUID = _IJMServer.GetUserGUID(SessionID); int result = _IJMServer.UpdateJobStatus(JMOwnJobRequest, UserGUID); if (result > 0) { Logger.Debug("Response: No response In Body,Process is Success"); return Request.CreateResponse(HttpStatusCode.OK); } else { switch (result) { case 0: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable insert Job Progress"; break; case -1: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to update Job Open status"; break; case -2: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to update Job Assigned status"; break; case -3: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to update Job Progress status"; break; case -4: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to update Job Abandon status"; break; case -5: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to update Job Suspended status"; break; case -6: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to update Job Complete status"; break; default: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; break; } response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage DeleteJob([FromBody]DeleteJobRequest pDeleteJobRequest) { Logger.Debug("Inside JM Controller- DeleteJob"); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { //SessionID = Request.Headers.LastOrDefault().Value.First(); SessionID = pDeleteJobRequest.SessionGUID; Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { int lRerVal = _IJMServer.DeleteJobs(pDeleteJobRequest, SessionID); if (lRerVal >= 0) { Logger.Debug("Delete Job Response: " + lRerVal.ToString()); return Request.CreateResponse(HttpStatusCode.OK); } else { switch (lRerVal) { case -1: error.ErrorMessage = "Upable to process the delete request"; break; case -2: error.ErrorMessage = "Job not found in the database"; break; case -3: error.ErrorMessage = "Delete error"; break; default: error.ErrorMessage = "Error while processing the delete"; break; } error.ErrorCode = HttpStatusCode.BadRequest; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public async Task<HttpResponseMessage> UploadFileMultipart() { //StringBuilder lretstring = new StringBuilder(); var response = new Dictionary<string, object>(); UploadJobAttachmentResponse lResponse = new UploadJobAttachmentResponse(); ErrorResponse error = new ErrorResponse(); // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { //lretstring.Append("Not MultipartContent"); error.ErrorCode = HttpStatusCode.UnsupportedMediaType; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); // response.Add("ResultResponse", lretstring.ToString()); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } else if (Request.Headers == null) { // lretstring.Append("Header is null"); error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); // response.Add("ResultResponse", lretstring.ToString()); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } string SessionID = string.Empty; string JobGUID = string.Empty; if (HttpContext.Current.Request.Form != null && HttpContext.Current.Request.Form.Count > 0) { // lretstring.Append("Inside Request Form"); SessionID = HttpContext.Current.Request.Form["SessionGUID"]; JobGUID = HttpContext.Current.Request.Form["JobGUID"]; } if (_IJMServer.ValidateUser(SessionID)) { // lretstring.Append("Valid User"); string lFilesRoot = _IJMServer.GetUploadFileAttachmetsPath(JobGUID, SessionID); if (null == lFilesRoot) { // lretstring.Append("Fileroot is null"); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); // response.Add("ResultResponse", lretstring.ToString()); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } else { // lretstring.Append("Inside else"); var lProvider = new MultipartFormDataStreamProvider(lFilesRoot); try { // Read the form data. await Request.Content.ReadAsMultipartAsync(lProvider); foreach (MultipartFileData file in lProvider.FileData) { string lDestFilePath = lFilesRoot + "/" + file.Headers.ContentDisposition.FileName; if (File.Exists(lDestFilePath)) { File.Delete(lDestFilePath); } File.Move(file.LocalFileName, lDestFilePath); //This is all files Logger.Debug("Request File Name: " + file.Headers.ContentDisposition.FileName); Logger.Debug("Server file path: " + file.LocalFileName); } response.Add("JobAttachmentUpload", lResponse); // response.Add("ResultResponse", lretstring.ToString()); Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); return Request.CreateResponse(HttpStatusCode.OK, response); } catch (System.Exception ex) { //lretstring.Append("Catch"); Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); // response.Add("ResultResponse", lretstring.ToString()); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } //string root = AppDomain.CurrentDomain.BaseDirectory + "formdata"; //var provider = new MultipartFormDataStreamProvider(root); //try //{ // // Read the form data. // await Request.Content.ReadAsMultipartAsync(provider); // foreach (var key in provider.FormData.AllKeys) // { // //This should be the JSON that contains the details about the file(s) uploaded // var val = provider.FormData.GetValues(key); // Trace.WriteLine(string.Format("{0}: {1}", key, val)); // } // foreach (MultipartFileData file in provider.FileData) // { // //This is all files // Trace.WriteLine(file.Headers.ContentDisposition.FileName); // Trace.WriteLine("Server file path: " + file.LocalFileName); // } // return Request.CreateResponse(HttpStatusCode.OK); //} //catch (System.Exception e) //{ // return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e); //} }
public HttpResponseMessage CreateVisitForPO([FromBody]CreateVisitForPORequest jobRequest) { Logger.Debug("Inside JM Controller- CreateVisitForPO"); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(jobRequest)); MobileJob lResponse = new MobileJob(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { Guid UserGUID = _IJMServer.GetUserGUID(SessionID); int errorCode = 0; lResponse = _IJMServer.CreateVisitForPO(jobRequest, UserGUID, ref errorCode); if (lResponse != null && errorCode == 0) { response.Add("Jobs", lResponse); Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); return Request.CreateResponse(HttpStatusCode.OK, response); } else if (errorCode == -1) { error.ErrorCode = HttpStatusCode.MultipleChoices; error.ErrorMessage = "Unable to create job, Store information is not defined"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } else if (errorCode == -2) { error.ErrorCode = HttpStatusCode.MultipleChoices; error.ErrorMessage = "Unable to create job, Customer information is not defined"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } else { error.ErrorCode = HttpStatusCode.MultipleChoices; error.ErrorMessage = "Unable to create job, not able to get PO details"; // error.ErrorMessage = "Unable to create job, as a job already in progress for the PO"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure: " + ex.Message.ToString(); response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage GetOrganization() { log4net.Config.XmlConfigurator.Configure(); ILog log = LogManager.GetLogger("Inside UM Controller- GetOrganization"); UMResponseOrganization umResponse = new UMResponseOrganization(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); umResponse.Organization = _IUMServer.GetOrganization(SessionID).Organization; } return Request.CreateResponse(HttpStatusCode.OK, umResponse); } catch (Exception ex) { log.Debug(ex.Message); ErrorResponse error = new ErrorResponse(); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; return Request.CreateResponse(HttpStatusCode.InternalServerError, error); } }
public HttpResponseMessage AssignJob([FromBody]AssignJobRequest AssignJobRequest) { Logger.Debug("Inside JM Controller- AssignJob"); Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(AssignJobRequest)); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); int lRetVal = 0; try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { System.Guid UserGUID = _IJMServer.GetUserGUID(SessionID); lRetVal = _IJMServer.AssignJob(AssignJobRequest, UserGUID); if (lRetVal > 0) { Logger.Debug("Response: No response In Body,Process is Success"); return Request.CreateResponse(HttpStatusCode.OK); } else { switch (lRetVal) { case 0: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to assigne the job to the user"; break; case -1: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Already assigned to another worker"; break; case -2: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Job already started so can't be assigned"; break; case -5: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Unable to update assign job record"; break; default: error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; break; } response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage CreateAccount([FromBody]LoginRequest pLoginRequest) { Logger.Debug("Inside UMController- Create Account"); //Logger.Debug("Request: " + new JavaScriptSerializer().Serialize(pLoginRequest)); CreateAccountResponse CreateAccountResponse = new CreateAccountResponse(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string[] lCred = Encoding.UTF8.GetString(Convert.FromBase64String(pLoginRequest.Cred)).Split(':'); if (lCred.Count() > 1) { pLoginRequest.UserName = lCred[0]; pLoginRequest.Password = lCred[1]; } CreateAccountResponse = _IUMServer.CreateAccount(pLoginRequest); if (CreateAccountResponse != null) { //Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(CreateAccountResponse)); response.Add("CreateAccountResponse", CreateAccountResponse); return Request.CreateResponse(HttpStatusCode.Created, response); } else { error.ErrorCode = HttpStatusCode.Conflict; error.ErrorMessage = "Unable to create account or account already exists"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Conflict, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }
public HttpResponseMessage GetPOList() { Logger.Debug("Inside JM Controller- GetPOList"); Logger.Debug("No Request Structure"); MobilePoList lResponse = new MobilePoList(); ErrorResponse error = new ErrorResponse(); var response = new Dictionary<string, object>(); try { string SessionID = Guid.Empty.ToString(); if (Request.Headers != null) { SessionID = Request.Headers.LastOrDefault().Value.First(); Logger.Debug("SessionID: " + SessionID.ToString()); if (_IJMServer.ValidateUser(SessionID)) { lResponse.POList = _IJMServer.GetPOList(SessionID); if (lResponse != null) { // response.Add("PO", lResponse); Logger.Debug("Response: " + new JavaScriptSerializer().Serialize(lResponse)); return Request.CreateResponse(HttpStatusCode.OK, lResponse); } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get PO List"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } else { error.ErrorCode = HttpStatusCode.Forbidden; error.ErrorMessage = "Session has expired, please login again"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.Forbidden, response); } } else { error.ErrorCode = HttpStatusCode.BadRequest; error.ErrorMessage = "Unable to get SessionID in Header"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.BadRequest, response); } } catch (Exception ex) { Logger.Error(ex.Message); error.ErrorCode = HttpStatusCode.InternalServerError; error.ErrorMessage = "Failure"; response.Add("ErrorResponse", error); return Request.CreateResponse(HttpStatusCode.InternalServerError, response); } }