public OfferControllerModule() { Post["ReDoMeApi/Offer/Create"] = parameters => { try { SendLogMessage("called ReDoMeApi/Offer/Create", System.Diagnostics.EventLogEntryType.SuccessAudit); var jsonString = this.Request.Body.AsString(); Offer offer = ReDoMeAPI.Offer.FromJson(jsonString); offer.selected = false; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); Int64 Offer_ID = Database.createOffer(offer); if (Offer_ID == 0) { ErrorAnswer answer = new ErrorAnswer("creating offer error"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse(Offer_ID.ToString(), HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error Offer/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/Offer/Create", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Post["ReDoMeApi/Offer/AddPhotos"] = parameters => { try { SendLogMessage("called ReDoMeApi/Offer/AddPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.offer_id.HasValue) { throw new Exception("Missing parameter offer_id"); } Int64 Offer_ID = this.Request.Query.offer_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.addPhotosToOffer(Offer_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 Offer/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/Offer/AddPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Put["ReDoMeApi/Offer/Accept"] = parameters => { try { SendLogMessage("called ReDoMeApi/Offer/Accept", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.offer_id.HasValue) { throw new Exception("Missing parameter offer_id"); } if (!this.Request.Query.req_id.HasValue) { throw new Exception("Missing parameter req_id"); } int Req_ID = this.Request.Query.req_id; int Offer_ID = this.Request.Query.offer_id; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); bool bRes = Database.acceptOffer(Req_ID, Offer_ID); if (!bRes) { ErrorAnswer answer = new ErrorAnswer("offer not found"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse("OK", HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error Offer/Accept: {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/Offer/Accept", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/Offer/Delete"] = parameters => { try { SendLogMessage("called ReDoMeApi/Offer/Delete", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.offer_id.HasValue) { throw new Exception("Missing parameter offer_id"); } int Offer_ID = this.Request.Query.offer_id; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); if (!Database.deleteOffer(Offer_ID)) { ErrorAnswer answer = new ErrorAnswer("offer not found"); return(ReDoMeAPIResponse.CreateResponse(answer.ToJson(), HttpStatusCode.OK)); } return(ReDoMeAPIResponse.CreateResponse("OK", HttpStatusCode.OK)); } catch (Exception exc) { string Err = $"Error Offer/Delete: {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/Offer/Delete", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/Offer/GetStatusesByBarber"] = parameters => { try { SendLogMessage("called ReDoMeApi/Offer/GetStatusesByBarber", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.barber.HasValue) { throw new Exception("Missing parameter Barber"); } string barberVkId = this.Request.Query.barber; RequestState state = RequestState.Any; if (this.Request.Query.state.HasValue) { state = (RequestState)((Int16)this.Request.Query.state); } //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); RequestWithOfferList offers = Database.getOffersState(barberVkId, state); 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 Offer/GetStatusesByBarber: {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/Offer/GetStatusesByBarber", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; Get["ReDoMeApi/Offer/GetPhotos"] = parameters => { try { SendLogMessage("called ReDoMeApi/Offer/GetPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit); if (!this.Request.Query.offer_id.HasValue) { throw new Exception("Missing parameter offer_id"); } int Offer_ID = this.Request.Query.offer_id; //if (User != Tracking.Options.MainOptions.WEBAPIUser || Password != Tracking.Options.MainOptions.WEBAPIPassword) // throw new Exception("Invalid password or login"); PhotoList photos = Database.getOfferPhotos(Offer_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 Offer/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/Offer/GetPhotos", System.Diagnostics.EventLogEntryType.SuccessAudit); } }; }
//--------------------------------------------- static public RequestWithOfferList getOffersState(string _vk_id, RequestState _state) { RequestWithOfferList offerList = new RequestWithOfferList(); offerList.items = new List <RequestWithOffer>(); 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, o.Offer_ID, o.Bar_VK_ID, o.sal_id, o.Offer_Cost, o.Offer_ForDate, o.Offer_Selected, o.Offer_Comment FROM Request r inner join Offer o ON r.req_id = o.Req_ID WHERE o.Bar_VK_ID = @BAR_VK_ID AND (req_status=@REQ_STATUS OR @REQ_STATUS = 0)" ; SqlCommand command = new SqlCommand(sqlExpression, connection); command.Parameters.Add(new SqlParameter("BAR_VK_ID", _vk_id)); command.Parameters.Add(new SqlParameter("REQ_STATUS", (Int16)_state)); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { RequestWithOffer item = new RequestWithOffer(); item.request = new Request(); item.offer = new Offer(); item.request.id = reader.GetInt64(0); if (!reader.IsDBNull(1)) { item.request.client_vk_id = reader.GetString(1); } item.request.client_name = reader.GetString(2); item.request.city = reader.GetString(3); item.request.type = (RequestType)reader.GetInt16(4); item.request.state = (RequestState)reader.GetInt16(5); if (!reader.IsDBNull(6)) { item.request.score = reader.GetInt16(6); } if (!reader.IsDBNull(7)) { item.request.comment = reader.GetString(7); } item.offer.id = reader.GetInt64(8); item.offer.req_id = reader.GetInt64(0); if (!reader.IsDBNull(9)) { item.offer.bar_vk_id = reader.GetString(9); } if (!reader.IsDBNull(10)) { item.offer.sal_id = reader.GetInt32(10); } item.offer.cost = reader.GetDouble(11); item.offer.date = reader.GetDateTime(12); item.offer.selected = reader.GetBoolean(13); if (!reader.IsDBNull(14)) { item.offer.comment = reader.GetString(14); } offerList.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 (RequestWithOffer req in offerList.items) { req.request.photos = getRequestPhotos(req.request.id); req.offer.photos = getOfferPhotos(req.offer.id); } return(offerList); }