예제 #1
0
 public IHttpActionResult CreateDelivery(string token, JDE_Deliveries 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;
             db.JDE_Deliveries.Add(item);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Utworzenie dostawy", 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());
     }
 }
예제 #2
0
        public IHttpActionResult EditDelivery(string token, int id, int UserId, JDE_Deliveries 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_Deliveries.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.DeliveryId == id);
                    if (items.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Edycja dostawy", 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_DeliveryExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }