public async Task <ActionResult> PutCallback([FromBody] PutBody body) { var id = ""; // TODO: Where does this come from? var request = await _context.Requests.SingleOrDefaultAsync(r => r.Id == id); if (request == null) { return(NotFound($"A request with an id of '{id}' could not be found.")); } request.Status = body.Status; request.Detail = body.Detail; request.Body = body.Detail; try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(NoContent()); }
public void Put([FromBody] JsonElement body) { string json = JsonSerializer.Serialize(body); PutBody putBody = JsonSerializer.Deserialize <PutBody>(json); int dirPathEnd = putBody.Path.LastIndexOf('\\'); string dirpath = putBody.Path.Substring(0, dirPathEnd); Directory.Move(putBody.Path, Path.Combine(dirpath, putBody.Name)); }
public async Task UpdateProductStock(string merchantNo, int value) { var body = new PutBody <int>(value, "Stock", "replace"); var httpContent = new StringContent(body.ToHttpBody()); var response = await _httpClient.PatchAsync($"{_apiUrl}products/{merchantNo}?apikey={_apiKey}", httpContent); var json = await response.Content.ReadAsStringAsync(); var contentProduct = JsonConvert.DeserializeObject <ResponsBody>(json); if (!contentProduct.Success) { throw new StockUpdateException(merchantNo); } }
public IHttpActionResult Clipboard([FromBody] PutBody putBody) { if (putBody == null) { throw new ArgumentNullException(nameof(putBody)); } if (putBody.Uid == null) { throw new ArgumentNullException(nameof(putBody.Uid)); } var inputUid = Guid.Parse(putBody.Uid); //todo improve this, hard coded as dev session id for now if (!CheckHeaderSession()) { //return Unauthorized(); } var createdAt = GetOriginCreatedAt(inputUid); if (!createdAt.HasValue) { throw new InvalidOperationException("Data already deleted, please reload to latest then edit"); } var path = GetFullClipboardDataPath(createdAt.Value); //ensure orig item and updated item in the same file if (!File.Exists(path)) { return(DtoResultV5.Success(this.Json, "no data")); } //perf - O(n) is 2n here, can be optimized to n var notes = ReadLskjson <Guid, DtoClipboardItem>(path, CollectLskjsonLineClipboard); var foundNote = notes.FirstOrDefault(n => n.Uid == inputUid); var foundChild = notes.FirstOrDefault(n => n.ParentUid == inputUid); //ensure the relation is a chain, not a tree if (foundChild != null) { throw new InvalidOperationException("Data already changed, please reload to latest then edit"); } if (foundNote != null) { var newNote = Utility.DeepClone(foundNote); newNote.Uid = Guid.NewGuid(); //reset newNote.Data = putBody.Data; //todo - replace with real UserId(get by session id) newNote.HasUpdated = true; newNote.LastUpdatedBy = Constants.DevUpdateUserId + DateTime.Now.ToString("dd"); newNote.LastUpdatedAt = DateTime.Now; newNote.ParentUid = foundNote.Uid; AppendNoteToFile(path, newNote); AppendObjectToFile(GetFullClipboardIndexPath(newNote.CreatedAt), DtoLskjsonIndex.From(newNote)); //return DtoResultV5.Success(Json, MapToJSNameConvention(newNote), "Data updated"); return(DtoResultV5.Success(Json, newNote, "Data updated")); //do the map on client side } else { return(DtoResultV5.Fail(Json, "The data you want to update may have been deleted")); } }
public IHttpActionResult Put(string id, [FromBody] PutBody body) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (body == null) { throw new ArgumentNullException(nameof(body)); } var perf = PerfCounter.NewThenCheck(this.ToString() + "." + MethodBase.GetCurrentMethod().Name); var fulfillmentPath = GetFullIntrospectionDataPath(DateTime.Now, IntrospectionDataType.Fulfillments); var antiSpamResult = PassAntiSpamDefender(fulfillmentPath, AuthMode.None); if (!antiSpamResult.Valid) { return(DtoResultV5.Fail(BadRequest, antiSpamResult.Message)); } perf.Check("anti spam end"); SyncRoutine(fulfillmentPath); perf.Check("sync routine end"); var fulfillments = ReadLskjson <Guid, RoutineFulfillment>(fulfillmentPath, CollectLskjsonLineIncludeDeleted); perf.Check("read fulfillment end"); var inputUid = Guid.Parse(id); var fulfill = fulfillments.FirstOrDefault(f => f.Uid == inputUid); if (fulfill == null) { return(DtoResultV5.Fail(BadRequest, "expired data found, please reload page first.")); } var offsetDays = int.Parse(antiSpamResult.Message); var date = DateTime.Now.AddDays(-1 * Math.Abs(offsetDays)); var record = new FulfillmentArchive(fulfill.Uid, body.LastRemark, date, "fixme-put", DateTime.Now); if (fulfill.StagedArchives == null) { fulfill.StagedArchives = new[] { record }; } else { var staged = fulfill.StagedArchives.ToList(); staged.Add(record); if (staged.Count >= Constants.LskFulfillmentActiveRecords + Constants.LskFulfillmentArchiveUnit) { const int startIndex = 0; var archiveUnit = staged.GetRange(startIndex, Constants.LskFulfillmentArchiveUnit); var archivePath = GetFullIntrospectionDataPath(DateTime.Now, IntrospectionDataType.Archives); AppendObjectToFile(archivePath, archiveUnit.ToArray()); staged.RemoveRange(startIndex, archiveUnit.Count); fulfill.HasArchived = true; } fulfill.StagedArchives = staged.ToArray(); } //fulfill.StagedArchives = fulfill.StagedArchives.Concat(new[] { record }).ToArray(); fulfill.UpdateBy = "fixme-update"; fulfill.UpdateAt = DateTime.Now; WriteToFile(fulfillmentPath, fulfillments); perf.End("override fulfill end", true); return(DtoResultV5.Success(Json, DtoRoutine.From(fulfill, false))); }