public IHttpActionResult EditPartPrice(string token, int id, int UserId, JDE_PartPrices item) { string methodName = System.Reflection.MethodInfo.GetCurrentMethod().Name; Logger.Info("Start {methodName}. Id={id}, UserId={UserId}", methodName, id, UserId); if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { string newItem = ""; try { var items = db.JDE_PartPrices.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.PartPriceId == id); if (items.Any()) { Logger.Info("{methodName}: Znalazłem odpowiednie PartPrice. Przystępuję do edycji Id={id}, UserId={UserId}", methodName, id, UserId); item.CreatedOn = items.FirstOrDefault().CreatedOn; //switch back to original createdOn date item.LmBy = UserId; item.LmOn = DateTime.Now; newItem = new JavaScriptSerializer().Serialize(item); JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Edycja ceny części", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault()), NewValue = new JavaScriptSerializer().Serialize(item) }; db.JDE_Logs.Add(Log); db.Entry(item).State = EntityState.Modified; try { db.SaveChanges(); Logger.Info("{methodName}: Edycja zakończona powodzeniem. Przystępuję do edycji Id={id}, UserId={UserId}", methodName, id, UserId); } catch (DbUpdateConcurrencyException) { if (!JDE_PartPriceExists(id)) { return(NotFound()); } else { throw; } } } } catch (Exception ex) { Logger.Error("Błąd w {methodName}. Id={id}, UserId={UserId}. Szczegóły: {Message}, nowa wartość: {newItem}", methodName, id, UserId, ex.ToString(), newItem); return(StatusCode(HttpStatusCode.InternalServerError)); } } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult CreatePartPrice(string token, JDE_PartPrices item, int UserId) { string methodName = System.Reflection.MethodInfo.GetCurrentMethod().Name; Logger.Info("Start {methodName}. PartId={PartId}, UserId={UserId}", methodName, item.PartId, UserId); if (token != null && token.Length > 0) { var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim()); if (tenants.Any()) { try { item.TenantId = tenants.FirstOrDefault().TenantId; item.CreatedOn = DateTime.Now; db.JDE_PartPrices.Add(item); db.SaveChanges(); JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Nowa cena części", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item) }; db.JDE_Logs.Add(Log); db.SaveChanges(); Logger.Info("{methodName}: Zapis zakończony powodzeniem. PartPriceId={PartPriceId}, UserId={UserId}", methodName, item.PartPriceId, UserId); return(Ok(item)); } catch (Exception ex) { Logger.Error("Błąd w {methodName}. PartPriceId={PartPriceId}, UserId={UserId}. Szczegóły: {Message}", methodName, item.PartPriceId, UserId, ex.ToString()); return(StatusCode(HttpStatusCode.InternalServerError)); } } else { return(NotFound()); } } else { return(NotFound()); } }