예제 #1
0
        //---------------------------------------------
        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);
                }
            };
        }
예제 #2
0
        //---------------------------------------------
        static public BarberList getBarbers()
        {
            BarberList barberList = new BarberList();

            barberList.items = new List <Barber>();
            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 bar_vk_id, sal_id, bar_name, bar_spec,
                        bar_city, bar_address, bar_phone, bar_about, bar_certs,
                        bar_raiting
                        FROM barber";
                SqlCommand    command = new SqlCommand(sqlExpression, connection);
                SqlDataReader reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    Barber barber = new Barber();
                    while (reader.Read())
                    {
                        barber       = new Barber();
                        barber.vk_id = reader.GetString(0);
                        if (!reader.IsDBNull(1))
                        {
                            barber.sal_id = reader.GetInt32(1);
                        }
                        barber.name = reader.GetString(2);
                        barber.spec = reader.GetString(3);
                        barber.city = reader.GetString(4);
                        if (!reader.IsDBNull(5))
                        {
                            barber.address = reader.GetString(5);
                        }
                        if (!reader.IsDBNull(6))
                        {
                            barber.phone = reader.GetString(6);
                        }
                        if (!reader.IsDBNull(7))
                        {
                            barber.about = reader.GetString(7);
                        }
                        if (!reader.IsDBNull(8))
                        {
                            barber.certs = reader.GetString(8);
                        }
                        barber.raiting = reader.GetInt32(9);
                    }
                    barberList.items.Add(barber);
                }
                reader.Close();
                connection.Close();
            }
            catch (Exception e)
            {
                SendLogMessage(e.Message, System.Diagnostics.EventLogEntryType.Error, e);
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(barberList);
        }