Exemplo n.º 1
0
 public IHttpActionResult CreateOrderItem(string token, JDE_OrderItems item, int UserId)
 {
     if (token != null && token.Length > 0)
     {
         var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
         if (tenants.Any())
         {
             item.TenantId  = tenants.FirstOrDefault().TenantId;
             item.CreatedOn = DateTime.Now;
             item.CreatedBy = UserId;
             db.JDE_OrderItems.Add(item);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Utworzenie pozycji w zamówieniu", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
             };
             db.JDE_Logs.Add(Log);
             db.SaveChanges();
             return(Ok(item));
         }
         else
         {
             return(NotFound());
         }
     }
     else
     {
         return(NotFound());
     }
 }
Exemplo n.º 2
0
        public HttpResponseMessage ArchiveOrderItem(string token, int id, int UserId)
        {
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    var items = db.JDE_OrderItems.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.OrderItemId == id);
                    if (items.Any())
                    {
                        JDE_OrderItems orgItem = items.FirstOrDefault();

                        orgItem.IsArchived = true;
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Archiwizacja pozycji zamówienia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault()), NewValue = ""
                        };
                        db.JDE_Logs.Add(Log);

                        try
                        {
                            db.Entry(orgItem).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!JDE_OrderItemExists(id))
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound));
                            }
                            else
                            {
                                throw;
                            }
                        }
                        catch (Exception ex)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
                        }
                    }
                }
            }
            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public IHttpActionResult EditOrderItem(string token, int id, int UserId, JDE_OrderItems item)
        {
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    var items = db.JDE_OrderItems.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.OrderItemId == id);
                    if (items.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Edycja pozycji w zamówieniu", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault()), NewValue = new JavaScriptSerializer().Serialize(item)
                        };
                        db.JDE_Logs.Add(Log);
                        item.LmBy            = UserId;
                        item.LmOn            = DateTime.Now;
                        db.Entry(item).State = EntityState.Modified;
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!JDE_OrderItemExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }