public async Task <IDataAccessDataResponse> GetResponseAsync(HttpContext httpContext, XDocument xml) { uint userId = httpContext.IsAuthenicatedPr3User(); if (userId > 0) { XElement data = xml.Element("Params"); if (data != null) { uint start = (uint?)data.Element("p_start") ?? throw new DataAccessProcedureMissingData(); uint count = (uint?)data.Element("p_count") ?? throw new DataAccessProcedureMissingData(); string category = (string)data.Element("p_category") ?? throw new DataAccessProcedureMissingData(); DataAccessGetMyStampsResponse response = new(category); foreach (uint stamp in await StampManager.GetMyStampsAsync(userId, category, start, count)) { response.AddStamp(stamp); } return(response); } else { throw new DataAccessProcedureMissingData(); } } else { return(new DataAccessErrorResponse("You are not logged in!")); } }
public async Task <IDataAccessDataResponse> GetResponseAsync(HttpContext httpContext, XDocument xml) { uint userId = httpContext.IsAuthenicatedPr3User(); if (userId > 0) { XElement data = xml.Element("Params"); if (data != null) { uint stampId = (uint?)data.Element("p_stamp_id") ?? throw new DataAccessProcedureMissingData(); await StampManager.DeleteStampAsync(stampId, userId); return(new DataAccessDeleteStampResponse()); } else { throw new DataAccessProcedureMissingData(); } } else { return(new DataAccessErrorResponse("You are not logged in!")); } }
public async Task <IDataAccessDataResponse> GetResponseAsync(HttpContext httpContext, XDocument xml) { uint userId = httpContext.IsAuthenicatedPr3User(); if (userId > 0) { XElement data = xml.Element("Params"); if (data != null) { string category = (string)data.Element("p_category") ?? throw new DataAccessProcedureMissingData(); uint count = await StampManager.CountMyStampsAsync(userId, category); return(new DataAccessCountMyStampsResponse(category, count)); } else { throw new DataAccessProcedureMissingData(); } } else { return(new DataAccessErrorResponse("You are not logged in!")); } }
public async Task <IDataAccessDataResponse> GetResponseAsync(HttpContext httpContext, XDocument xml) { uint userId = httpContext.IsAuthenicatedPr3User(); if (userId > 0) { XElement data = xml.Element("Params"); if (data != null) { string title = (string)data.Element("p_title") ?? throw new DataAccessProcedureMissingData(); if (title.Length < SaveStampProcedure.TITLE_MIN_LENGTH || title.Length > SaveStampProcedure.TITLE_MAX_LENGTH) { return(new DataAccessErrorResponse($"Stamp title must be between {SaveStampProcedure.TITLE_MIN_LENGTH} and {SaveStampProcedure.TITLE_MAX_LENGTH} chars long!")); } string description = (string)data.Element("p_comment") ?? throw new DataAccessProcedureMissingData(); if (description.Length > SaveStampProcedure.DESCRIPTION_MAX_LENGTH) { return(new DataAccessErrorResponse($"Stamp comment can't be longer than {SaveStampProcedure.DESCRIPTION_MAX_LENGTH} chars long!")); } string category = (string)data.Element("p_category") ?? throw new DataAccessProcedureMissingData(); if (category.Length > SaveStampProcedure.CATEGORY_MAX_LENGTH) { return(new DataAccessErrorResponse($"Stamp category can't be longer than {SaveStampProcedure.CATEGORY_MAX_LENGTH} chars long!")); } string art = (string)data.Element("p_art") ?? throw new DataAccessProcedureMissingData(); bool success = await StampManager.SaveStampAsync(userId, title, category, description, art); if (success) { return(new DataAccessSaveStampResponse(true)); } else { return(new DataAccessSaveStampResponse()); } } else { throw new DataAccessProcedureMissingData(); } } else { return(new DataAccessSaveStampResponse()); } }
public async Task <IDataAccessDataResponse> GetResponseAsync(HttpContext httpContext, XDocument xml) { uint userId = httpContext.IsAuthenicatedPr3User(); if (userId > 0) { DataAccessGetMyStampCategories categories = new(); foreach (string category in await StampManager.GetMyStampCategoriesAsync(userId)) { categories.AddCategory(category); } return(categories); } else { return(new DataAccessErrorResponse("You are not logged in!")); } }
public async Task <IDataAccessDataResponse> GetResponseAsync(HttpContext httpContext, XDocument xml) { XElement data = xml.Element("Params"); if (data != null) { uint[] stampIds = ((string)data.Element("p_stamp_array") ?? throw new DataAccessProcedureMissingData()).Split(',').Select((b) => uint.Parse(b)).ToArray(); if (stampIds.Length > 0) { DataAccessGetManyStampsResponse response = new(); IList <StampData> stamps = await StampManager.GetStampsAsync(stampIds); foreach (StampData block in stamps) { response.AddStamp(block); } if (stamps.Count != stampIds.Length) { foreach (uint blockId in stampIds) { if (!stamps.Any((b) => b.Id == blockId)) { response.AddStamp(StampData.GetDeletedStamp(blockId)); } } } return(response); } else { return(new DataAccessGetManyStampsResponse()); } } else { throw new DataAccessProcedureMissingData(); } }
private void Start() { stampManager = GetComponentInParent <StampManager>(); }