Esempio n. 1
0
 public IHttpActionResult CreatePlaceAction(string token, JDE_PlaceActions 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_PlaceActions.Add(item);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Utworzenie przypisania czynności do zasobu", 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());
     }
 }
Esempio n. 2
0
        public IHttpActionResult EditPlaceAction(string token, int id, int UserId, JDE_PlaceActions 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_PlaceActions.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.PlaceActionId == id);
                    if (items.Any())
                    {
                        string descr = "Edycja przypisania czynności do zasobu";
                        item.LmOn = DateTime.Now;
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = descr, 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();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!JDE_PlaceActionExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }