//--------------------------------------------- static public bool addPhotosToOffer(Int64 _offer_ID, PhotoList _photos) { SqlConnection connection = new SqlConnection(Options.MainOptions.ConnectionString); try { connection.Open(); AddPhotoCommand command = new AddPhotoCommand(connection); foreach (Photo photo in _photos.items) { command.AddToOffer(_offer_ID, photo); } connection.Close(); return(true); } catch (Exception e) { SendLogMessage(e.Message, System.Diagnostics.EventLogEntryType.Error, e); throw e; } finally { if (connection != null) { connection.Close(); } } }
//--------------------------------------------- static public PhotoList getBarberPhotos(string _barber_vk_id, PhotoType _photoType) { PhotoList photoList = new PhotoList(); photoList.listType = _photoType; photoList.items = new List <Photo>(); 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 photo_id, Photo_Goal, Photo_VK_Link, Photo_Content, Photo_Comment from photo p where p.Bar_VK_ID = @BAR_VK_ID AND p.photo_goal = @PHOTO_TYPE" ; SqlCommand command = new SqlCommand(sqlExpression, connection); command.Parameters.Add(new SqlParameter("BAR_VK_ID", _barber_vk_id)); command.Parameters.Add(new SqlParameter("PHOTO_TYPE", (int)_photoType)); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Photo item = new Photo(); item.id = reader.GetInt64(0); item.type = (PhotoType)reader.GetInt16(1); if (!reader.IsDBNull(2)) { item.vk_link = reader.GetString(2); } if (!reader.IsDBNull(3)) { item.content = reader.GetString(3); } if (!reader.IsDBNull(4)) { item.comment = reader.GetString(4); } photoList.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(); } } return(photoList); }
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); } }; }
//--------------------------------------------- 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); } }; }
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); } }; }