コード例 #1
0
        public RequestControllerModule()
        {
            Post["ReDoMeApi/Request/Create"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/Create", System.Diagnostics.EventLogEntryType.SuccessAudit);
                    var     jsonString = this.Request.Body.AsString();
                    Request request    = ReDoMeAPI.Request.FromJson(jsonString);
                    request.state = RequestState.New;
                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    Int64 Req_ID = Database.createRequest(request);
                    if (Req_ID == 0)
                    {
                        ErrorAnswer answer = new ErrorAnswer("creating request error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse(Req_ID.ToString(), HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/Create: {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/Request/Create", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };
            Post["ReDoMeApi/Request/AddPhotos"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/AddPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit);

                    if (!this.Request.Query.req_id.HasValue)
                    {
                        throw new Exception("Missing parameter req_id");
                    }

                    Int64 Req_ID = this.Request.Query.req_id;

                    var       jsonString = this.Request.Body.AsString();
                    PhotoList photos     = ReDoMeAPI.PhotoList.FromJson(jsonString);
                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    if (!Database.addPhotosToRequest(Req_ID, photos))
                    {
                        ErrorAnswer answer = new ErrorAnswer("adding photos error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse("OK", HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/AddPhotos: {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/Request/AddPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };
            Get["ReDoMeApi/Request/GetOffers"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/GetOffers", System.Diagnostics.EventLogEntryType.SuccessAudit);

                    if (!this.Request.Query.req_id.HasValue)
                    {
                        throw new Exception("Missing parameter req_id");
                    }

                    int Req_ID = this.Request.Query.req_id;

                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    OfferList offers = Database.getOffersForRequest(Req_ID);
                    if (offers == null)
                    {
                        ErrorAnswer answer = new ErrorAnswer("server error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse(offers.ToJson(), HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/GetOffers: {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/Request/GetOffers", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };
            Get["ReDoMeApi/Request/GetPhotos"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/GetPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit);

                    if (!this.Request.Query.req_id.HasValue)
                    {
                        throw new Exception("Missing parameter req_id");
                    }

                    int Req_ID = this.Request.Query.req_id;

                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    PhotoList photos = Database.getRequestPhotos(Req_ID);
                    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 Request/GetPhotos: {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/Request/GetPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };
            Get["ReDoMeApi/Request/SetScore"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/SetScore", System.Diagnostics.EventLogEntryType.SuccessAudit);

                    if (!this.Request.Query.req_id.HasValue)
                    {
                        throw new Exception("Missing parameter req_id");
                    }
                    if (!this.Request.Query.score.HasValue)
                    {
                        throw new Exception("Missing parameter score");
                    }

                    int Req_ID = this.Request.Query.req_id;
                    int Score  = this.Request.Query.score;

                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    if (!Database.setScoreForRequest(Req_ID, Score))
                    {
                        ErrorAnswer answer = new ErrorAnswer("server error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse("OK", HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/SetScore: {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/Request/SetScore", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };

            Get["ReDoMeApi/Request/GetAllNew"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/GetAllNew", System.Diagnostics.EventLogEntryType.SuccessAudit);


                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    RequestList requests = Database.getRequests(RequestState.New);
                    if (requests == null)
                    {
                        ErrorAnswer answer = new ErrorAnswer("server error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse(requests.ToJson(), HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/GetAllNew: {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/Request/GetAllNew", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };

            Get["ReDoMeApi/Request/GetAll"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/GetAll", System.Diagnostics.EventLogEntryType.SuccessAudit);


                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    RequestList requests = Database.getRequests(RequestState.Any);
                    if (requests == null)
                    {
                        ErrorAnswer answer = new ErrorAnswer("server error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse(requests.ToJson(), HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/GetAll: {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/Request/GetAll", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };
            Get["ReDoMeApi/Request/GetByClient"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/GetByClient", System.Diagnostics.EventLogEntryType.SuccessAudit);

                    if (!this.Request.Query.client.HasValue)
                    {
                        throw new Exception("Missing parameter Client");
                    }

                    string clientVkId = this.Request.Query.client;


                    //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword)
                    //    throw new Exception("Invalid password or login");

                    RequestList requests = Database.getRequestsByClient(clientVkId);
                    if (requests == null)
                    {
                        ErrorAnswer answer = new ErrorAnswer("server error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse(requests.ToJson(), HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/GetByClient: {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/Request/GetByClient", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };
            Get["ReDoMeApi/Request/GetByBarber"] = parameters =>
            {
                try
                {
                    SendLogMessage("called ReDoMeApi/Request/GetByBarber", 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");

                    RequestList requests = Database.getRequestsByMaster(barberVkId);
                    if (requests == null)
                    {
                        ErrorAnswer answer = new ErrorAnswer("server error");
                        return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK));
                    }
                    return(ReDoMeAPIResponse.CreateResponse(requests.ToJson(), HttpStatusCode.OK));
                }
                catch (Exception exc)
                {
                    string Err = $"Error Request/GetByBarber: {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/Request/GetByBarber", System.Diagnostics.EventLogEntryType.SuccessAudit);
                }
            };
        }
コード例 #2
0
        //---------------------------------------------
        static public RequestList getRequestsByMaster(string _vk_id)
        {
            RequestList requestList = new RequestList();

            requestList.items = new List <Request>();
            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 r.req_id, req_vk_id, req_clientname, req_city, req_type, req_status, work_score, req_comment, ISNULL(o.offer_count, 0) offer_count
                        FROM Request r left join
	                        (
		                        SELECT count(offer_id) as offer_count, req_id
			                        FROM Offer o 
			                        GROUP BY req_id
	                        ) o on r.req_id = o.req_id inner join
			                (
				                SELECT count(offer_id) as offer_count, req_id
					                FROM Offer o
					                WHERE o.Bar_VK_ID = @BAR_VK_ID
			                        GROUP BY req_id
			                ) o2 on r.Req_ID = o2.Req_ID"            ;
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add(new SqlParameter("BAR_VK_ID", _vk_id));
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Request item = new Request();
                        item.id = reader.GetInt64(0);
                        if (!reader.IsDBNull(1))
                        {
                            item.client_vk_id = reader.GetString(1);
                        }
                        item.client_name = reader.GetString(2);
                        item.city        = reader.GetString(3);
                        item.type        = (RequestType)reader.GetInt16(4);
                        item.state       = (RequestState)reader.GetInt16(5);
                        if (!reader.IsDBNull(6))
                        {
                            item.score = reader.GetInt16(6);
                        }
                        if (!reader.IsDBNull(7))
                        {
                            item.comment = reader.GetString(7);
                        }
                        item.offer_count = reader.GetInt32(8);
                        requestList.items.Add(item);
                    }
                }
                reader.Close();
                connection.Close();
            }
            catch (Exception e)
            {
                SendLogMessage(e.Message, System.Diagnostics.EventLogEntryType.Error, e);
                throw e;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            foreach (Request req in requestList.items)
            {
                req.photos = getRequestPhotos(req.id);
            }

            return(requestList);
        }