예제 #1
0
 public IHttpActionResult CreateCompanyType(string token, JDE_CompanyTypes 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_CompanyTypes.Add(item);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Utworzenie typu firmy", 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 EditCompanyType(string token, int id, int UserId, JDE_CompanyTypes 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_CompanyTypes.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.CompanyTypeId == id);
                    if (items.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Edycja typu firmy", 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_CompanyTypeExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }