public async Task <Zongsoft.IO.FileInfo> Upload(uint id, string args) { if (string.IsNullOrWhiteSpace(args)) { throw HttpResponseExceptionUtility.BadRequest("Missing the args."); } if (!string.Equals(args, "avatar", StringComparison.OrdinalIgnoreCase) && !string.Equals(args, "photo", StringComparison.OrdinalIgnoreCase)) { throw HttpResponseExceptionUtility.BadRequest($"Invalid '{args}' value of the argument."); } var path = Zongsoft.IO.Path.Parse(this.DataService.GetFilePath(id, args)); var accessor = new Zongsoft.Web.WebFileAccessor(); var info = (await accessor.Write(this.Request, path.DirectoryUrl, e => e.FileName = path.FileName)).FirstOrDefault(); if (info != null) { if (string.Equals(args, "avatar", StringComparison.OrdinalIgnoreCase)) { this.DataService.SetAvatar(id, info.Path.Url); } else if (string.Equals(args, "photo", StringComparison.OrdinalIgnoreCase)) { this.DataService.SetPhotoPath(id, info.Path.Url); } info.Url = info.Url + "?" + Zongsoft.Common.RandomGenerator.GenerateString(); } return(info); }
public object GetStatistics(uint id, [FromRoute("args")] string kind = null) { if (string.IsNullOrWhiteSpace(kind)) { throw HttpResponseExceptionUtility.BadRequest("Missing kind of the statistics."); } switch (kind.ToLowerInvariant()) { case "message": return(null); //return this.DataService.GetMessageStatistics(id); default: throw HttpResponseExceptionUtility.BadRequest("Invalid kind of the statistics."); } }
public override void Patch(string id, IDictionary <string, object> data) { uint userId; if (!uint.TryParse(id, out userId)) { throw HttpResponseExceptionUtility.BadRequest($"The '{id}' id value must be a integer."); } if (data.TryGetValue("Status", out var status) && status != null) { if (!this.DataService.SetStatus(userId, Zongsoft.Common.Convert.ConvertValue(status, UserStatus.Active))) { throw new HttpResponseException(System.Net.HttpStatusCode.NotFound); } } }
public int GetCount(uint id, string args) { if (string.IsNullOrEmpty(args)) { throw HttpResponseExceptionUtility.BadRequest("Missing arguments of the request."); } switch (args.ToLowerInvariant()) { case "unread": case "message-unread": return(this.DataService.GetMessageUnreadCount(id)); case "message": case "message-total": return(this.DataService.GetMessageTotalCount(id)); default: throw HttpResponseExceptionUtility.BadRequest("Invalid argument value."); } }