//--------------------------------------------- static public SalonList getSalons() { SalonList salonList = new SalonList(); salonList.items = new List <Salon>(); SqlConnection connection = new SqlConnection(Options.MainOptions.ConnectionString); try { connection.Open(); //string sqlExpression = "SELECT B.[BRA_ID], B.[BRA_NAME] FROM [WORKER_DOCTOR] DW, [WORKER_BRANCH] WB, [BRANCH] B WHERE DW.[DOCT_ID] = @DOCT_ID AND DW.[WORK_ID] = WB.[WORK_ID] AND WB.[BRA_ID] = B.[BRA_ID] AND DW.[MEDORG_ID] = @MEDORG_ID AND DW.[MEDORG_ID] = B.[MEDORG_ID] AND WB.[MEDORG_ID] = B.[MEDORG_ID] AND [TIME_PER_ID] IS NOT NULL GROUP BY B.[BRA_ID], B.[BRA_NAME] "; string sqlExpression = @"SELECT Sal_ID, Sal_VK_ID, Sal_Name, Sal_City, Sal_Address, Sal_Phone, Sal_Raiting FROM Salon s"; SqlCommand command = new SqlCommand(sqlExpression, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { Salon salon = new Salon(); while (reader.Read()) { salon = new Salon(); salon.id = reader.GetInt32(0); if (!reader.IsDBNull(1)) { salon.vk_id = reader.GetString(1); } salon.name = reader.GetString(2); salon.city = reader.GetString(3); if (!reader.IsDBNull(4)) { salon.address = reader.GetString(4); } salon.phone = reader.GetString(5); salon.raiting = reader.GetInt32(6); } salonList.items.Add(salon); } reader.Close(); connection.Close(); } catch (Exception e) { SendLogMessage(e.Message, System.Diagnostics.EventLogEntryType.Error, e); return(null); } finally { if (connection != null) { connection.Close(); } } return(salonList); }
//--------------------------------------------- public MainControllerModule() { Get["ReDoMeApi/GetSalon"] = parameters => { try { SendLogMessage("called ReDoMeApi/GetSalon", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.barber.HasValue) { throw new Exception("Missing parameter Barber"); } string barberVkId = this.Request.Query.barber; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); Salon salon = Database.getSalonByBarber(barberVkId); if (salon == null) { ErrorAnswer answer = new ErrorAnswer("salon not found"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(salon.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error GetSalon: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/GetSalon", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/GetSalonById"] = parameters => { try { SendLogMessage("called ReDoMeApi/GetSalonById", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.sal_id.HasValue) { throw new Exception("Missing parameter sal_id"); } int sal_ID = this.Request.Query.sal_id; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); Salon salon = Database.getSalonByID(sal_ID); if (salon == null) { ErrorAnswer answer = new ErrorAnswer("salon not found"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(salon.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error GetSalonById: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/GetSalonById", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/GetAllSalons"] = parameters => { try { SendLogMessage("called ReDoMeApi/GetAllSalons", System.Diagnostics.EventLogEntryType.SuccessAudit); //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); SalonList salonList = Database.getSalons(); if (salonList == null) { ErrorAnswer answer = new ErrorAnswer("server error"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(salonList.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error GetAllSalons: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/GetAllSalons", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/GetSalonPortfolio"] = parameters => { try { SendLogMessage("called ReDoMeApi/GetSalonPortfolio", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.sal_id.HasValue) { throw new Exception("Missing parameter sal_id"); } int sal_ID = this.Request.Query.sal_id; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); PhotoList photos = Database.getSalonPhotos(sal_ID, PhotoType.PortfolioSalon); if (photos == null) { ErrorAnswer answer = new ErrorAnswer("server error"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(photos.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error GetSalonPortfolio: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/GetSalonPortfolio", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/GetAllBarbers"] = parameters => { try { SendLogMessage("called ReDoMeApi/GetAllBarbers", System.Diagnostics.EventLogEntryType.SuccessAudit); BarberList barberList = Database.getBarbers(); if (barberList == null) { ErrorAnswer answer = new ErrorAnswer("server error"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(barberList.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error GetAllBarbers: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/GetAllBarbers", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/GetBarber"] = parameters => { try { SendLogMessage("called ReDoMeApi/GetBarber", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.barber.HasValue) { throw new Exception("Missing parameter barber"); } string barber_vk_id = this.Request.Query.barber; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); Barber barber = Database.getBarber(barber_vk_id); if (barber == null) { ErrorAnswer answer = new ErrorAnswer("barber not found"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(barber.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error GetBarber: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/GetBarber", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/GetBarberPortfolio"] = parameters => { try { SendLogMessage("called ReDoMeApi/GetBarberPortfolio", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.barber.HasValue) { throw new Exception("Missing parameter barber"); } string barber_vk_id = this.Request.Query.barber; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); PhotoList photos = Database.getBarberPhotos(barber_vk_id, PhotoType.PortfolioMaster); if (photos == null) { ErrorAnswer answer = new ErrorAnswer("server error"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(photos.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error GetBarberPortfolio: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/GetBarberPortfolio", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/getStarByFace"] = parameters => { try { SendLogMessage("called ReDoMeApi/getStarByFace", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.photo_link.HasValue) { throw new Exception("Missing parameter photo_link"); } string photo_link = this.Request.Query.photo_link; StarByFaceList faceList = StarByFaceClient.GetStarsList(photo_link); //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); //PhotoList photos = Database.getBarberPhotos(barber_vk_id, PhotoType.PortfolioMaster); //if (photos == null) //{ // ErrorAnswer answer = new ErrorAnswer("server error"); // return ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK); //} return(ReDoMeAPIResponse.CreateResponse(faceList.ToJson(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error getStarByFace: {exc.Message}"; SendLogMessage(Err, System.Diagnostics.EventLogEntryType.Error); ErrorAnswer answer = new ErrorAnswer(exc.Message); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } finally { SendLogMessage("ended ReDoMeApi/getStarByFace", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; }