Exemple #1
0
 public IHttpActionResult CreateArea(string token, JDE_Areas 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;
             db.JDE_Areas.Add(item);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Utworzenie obszaru", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
             };
             db.JDE_Logs.Add(Log);
             db.SaveChanges();
             return(Ok(item));
             //return CreatedAtRoute("DefaultApi", new { id = item.AreaId }, item);
         }
         else
         {
             return(NotFound());
         }
     }
     else
     {
         return(NotFound());
     }
 }
Exemple #2
0
 public IHttpActionResult CreateHandling(string token, JDE_Handlings 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.StartedOn = DateTime.Now;
             db.JDE_Handlings.Add(item);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Rozpoczęcie obsługi", 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());
     }
 }
        public IHttpActionResult DeleteOrderItem(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.Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.OrderItemId == id);
                    if (items.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Usunięcie pozycji w zamówieniu", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault())
                        };
                        db.JDE_OrderItems.Remove(items.FirstOrDefault());
                        db.JDE_Logs.Add(Log);
                        db.SaveChanges();

                        return(Ok(items.FirstOrDefault()));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #4
0
 public IHttpActionResult CreateUser(string token, JDE_Users jDE_Users, int UserId)
 {
     if (token != null && token.Length > 0)
     {
         var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
         if (tenants.Any())
         {
             jDE_Users.TenantId = tenants.FirstOrDefault().TenantId;
             db.JDE_Users.Add(jDE_Users);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Utworzenie użytkownika", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(jDE_Users)
             };
             db.JDE_Logs.Add(Log);
             db.SaveChanges();
             return(Ok(jDE_Users));
             //return CreatedAtRoute("DefaultApi", new { id = jDE_Users.UserId }, jDE_Users);
         }
         else
         {
             return(NotFound());
         }
     }
     else
     {
         return(NotFound());
     }
 }
Exemple #5
0
        public async static Task CompleteProcessAsync(DbModel db, int tenantId, JDE_Processes item, int UserId, string reasonForClosure = null)
        {
            string OldValue = new JavaScriptSerializer().Serialize(item);

            item.FinishedOn   = DateTime.Now;
            item.FinishedBy   = UserId;
            item.IsActive     = false;
            item.IsCompleted  = true;
            item.IsFrozen     = false;
            item.LastStatus   = (int)ProcessStatus.Finished;
            item.LastStatusBy = UserId;
            item.LastStatusOn = DateTime.Now;
            var User = db.JDE_Users.AsNoTracking().Where(u => u.UserId == UserId).FirstOrDefault();

            if (reasonForClosure == null)
            {
                item.Output = $"Przymusowe zamknięcie zgłoszenia przez {User.Name + " " + User.Surname}";
            }
            else
            {
                item.Output = reasonForClosure;
            }
            await CompleteProcessesHandlingsAsync(db, item.ProcessId, UserId);

            JDE_Logs Log = new JDE_Logs {
                UserId = UserId, Description = "Zamknięcie zgłoszenia", TenantId = tenantId, Timestamp = DateTime.Now, OldValue = OldValue, NewValue = new JavaScriptSerializer().Serialize(item)
            };

            db.JDE_Logs.Add(Log);
            db.Entry(item).State = EntityState.Modified;
            //db.SaveChanges();
        }
Exemple #6
0
        public IHttpActionResult DeleteProcessAssign(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_ProcessAssigns.Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.ProcessAssignId == id);
                    if (items.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Usunięcie przypisania zgłoszenia do użytkownika", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault())
                        };
                        db.JDE_ProcessAssigns.Remove(items.FirstOrDefault());
                        db.JDE_Logs.Add(Log);
                        db.SaveChanges();

                        return(Ok(items.FirstOrDefault()));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #7
0
 public IHttpActionResult CreateProcessAssign(string token, JDE_ProcessAssigns 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_ProcessAssigns.Add(item);
             db.SaveChanges();
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Utworzenie przypisania zgłoszenia do użytkownika", 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());
     }
 }
 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());
     }
 }
Exemple #9
0
        public HttpResponseMessage ArchiveOrder(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_Orders.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.OrderId == id);
                    if (items.Any())
                    {
                        JDE_Orders orgItem = items.FirstOrDefault();

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

                        //Archive child OrderItems
                        var orderItems = db.JDE_OrderItems.Where(i => i.OrderId == orgItem.OrderId);
                        if (orderItems.Any())
                        {
                            foreach (var item in orderItems)
                            {
                                item.IsArchived = true;
                                JDE_Logs ItemLog = new JDE_Logs {
                                    UserId = UserId, Description = "Archiwizacja pozycji zamówienia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(orderItems.FirstOrDefault()), NewValue = new JavaScriptSerializer().Serialize(item)
                                };
                                db.JDE_Logs.Add(Log);
                                db.Entry(item).State = EntityState.Modified;
                            }
                        }

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!JDE_OrderExists(id))
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound));
                            }
                            else
                            {
                                throw;
                            }
                        }
                        catch (Exception ex)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
                        }
                    }
                }
            }
            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
Exemple #10
0
 public IHttpActionResult EditProcessAction(string token, int id, int UserId, JDE_ProcessActions item)
 {
     Logger.Info("Start EditProcessAction. Id={id}, UserId={UserId}", id, 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_ProcessActions.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.ProcessActionId == id);
             if (items.Any())
             {
                 string newItem = "";
                 try
                 {
                     item.CreatedOn = items.FirstOrDefault().CreatedOn; //switch back to original createdOn date
                     item.LmOn      = DateTime.Now;
                     item.LmBy      = UserId;
                     item.TenantId  = items.FirstOrDefault().TenantId;
                     string descr = "Edycja przypisania czynności do zgłoszenia";
                     newItem = new JavaScriptSerializer().Serialize(item);
                     JDE_Logs Log = new JDE_Logs {
                         UserId = UserId, Description = descr, TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault()), NewValue = newItem
                     };
                     db.JDE_Logs.Add(Log);
                     db.Entry(item).State = EntityState.Modified;
                     try
                     {
                         db.SaveChanges();
                     }
                     catch (DbUpdateConcurrencyException DbEx)
                     {
                         Logger.Error("Błąd DbUpdateConcurrencyException w EditProcessAction. Id={id}, UserId={UserId}. Szczegóły: {Message}, nowa wartość: {newItem}", id, UserId, DbEx.ToString(), newItem);
                         if (!JDE_ProcessActionExists(id))
                         {
                             return(NotFound());
                         }
                         else
                         {
                             return(InternalServerError());
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Logger.Error("Błąd w EditProcessAction. Id={id}, UserId={UserId}. Szczegóły: {Message}, nowa wartość: {newItem}", id, UserId, ex.ToString(), newItem);
                     return(InternalServerError());
                 }
             }
             else
             {
                 Logger.Info("ProcessAction Id={id} nie zostało znalezione..", id);
             }
         }
     }
     Logger.Info("Koniec EditProcessAction. Id={id}, UserId={UserId}", id, UserId);
     return(StatusCode(HttpStatusCode.NoContent));
 }
Exemple #11
0
        public HttpResponseMessage CreatePart(string token, string PartJson, int UserId)
        {
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    JavaScriptSerializer jss  = new JavaScriptSerializer();
                    JDE_Parts            item = jss.Deserialize <JDE_Parts>(PartJson);

                    var httpRequest = HttpContext.Current.Request;
                    if (httpRequest.ContentLength > 0)
                    {
                        if (httpRequest.ContentLength > Static.RuntimeSettings.MaxFileContentLength)
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, $"{item.Name} przekracza dopuszczalną wielość pliku ({Static.RuntimeSettings.MaxFileContentLength} MB) i został odrzucony"));
                        }

                        //create unique token unless the file already exists
                        item.Token    = Static.Utilities.GetToken();
                        item.TenantId = tenants.FirstOrDefault().TenantId;
                        var    postedFile = httpRequest.Files[0];
                        string filePath   = "";
                        if (postedFile != null && postedFile.ContentLength > 0)
                        {
                            var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));

                            filePath = $"{Static.RuntimeSettings.Path2Files}{item.Token + ext.ToLower()}";

                            postedFile.SaveAs(filePath);
                            Static.Utilities.ProduceThumbnail(filePath);
                            item.Image = item.Token + ext.ToLower();
                        }
                    }

                    item.TenantId  = tenants.FirstOrDefault().TenantId;
                    item.CreatedOn = DateTime.Now;
                    db.JDE_Parts.Add(item);
                    db.SaveChanges();
                    JDE_Logs Log = new JDE_Logs {
                        UserId = UserId, Description = "Utworzenie części", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
                    };
                    db.JDE_Logs.Add(Log);
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.Created, item));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
 public IHttpActionResult GetActionTypeByName(string token, string name, int UserId)
 {
     if (token != null && token.Length > 0)
     {
         var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
         if (tenants.Any())
         {
             if (JDE_ActionTypesExists(name))
             {
                 //there's action type of given name, return it
                 var item = db.JDE_ActionTypes.Where(i => i.Name.Equals(name.Trim())).FirstOrDefault();
                 return(Ok(item));
             }
             else
             {
                 //there's NO action type of given name, create it and return it
                 JDE_ActionTypes nAt = new JDE_ActionTypes
                 {
                     Name                     = name.Trim(),
                     Description              = null,
                     MesSync                  = true,
                     RequireInitialDiagnosis  = true,
                     ShowInPlanning           = false,
                     AllowDuplicates          = true,
                     RequireQrToStart         = false,
                     RequireQrToFinish        = false,
                     ClosePreviousInSamePlace = false,
                     PartsApplicable          = false,
                     ActionsApplicable        = false,
                     RequireUsersAssignment   = false,
                     ShowOnDashboard          = false,
                     Leaveable                = true,
                     CreatedBy                = UserId,
                     CreatedOn                = DateTime.Now,
                     TenantId                 = tenants.FirstOrDefault().TenantId
                 };
                 db.JDE_ActionTypes.Add(nAt);
                 db.SaveChanges();
                 JDE_Logs Log = new JDE_Logs {
                     UserId = UserId, Description = "Utworzenie typu złoszenia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(nAt)
                 };
                 db.JDE_Logs.Add(Log);
                 db.SaveChanges();
                 return(Ok(nAt));
             }
         }
         else
         {
             return(NotFound());
         }
     }
     else
     {
         return(NotFound());
     }
 }
        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));
        }
Exemple #14
0
        public IHttpActionResult EditPart(string token, int id, int UserId, JDE_Parts item, bool DeleteImage = false)
        {
            Logger.Info("EditPart. Start. This is version without a file");
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    var items = db.JDE_Parts.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.PartId == id);
                    if (items.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Edycja 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);
                        item.LmBy = UserId;
                        item.LmOn = DateTime.Now;
                        // Check if to remove image
                        if (DeleteImage)
                        {
                            string oFileName = item.Image;
                            if (!string.IsNullOrEmpty(oFileName))
                            {
                                // There was a file, must delete it first
                                System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Files, oFileName));
                                System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Thumbs, oFileName));
                            }
                            item.Image = null;
                        }


                        db.Entry(item).State = EntityState.Modified;
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!JDE_PartExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #15
0
        public IHttpActionResult EditHandling(string token, int id, int UserId, JDE_Handlings 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_Handlings.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.HandlingId == id);
                    if (items.Any())
                    {
                        if (items.FirstOrDefault().StartedOn != null)
                        {
                            item.StartedOn = items.FirstOrDefault().StartedOn;
                        }
                        string descr = "Edycja obsługi";
                        if (items.FirstOrDefault().FinishedOn == null && item.FinishedOn != null)
                        {
                            //this has just been finished. Replace user's finish time with server time
                            item.FinishedOn = DateTime.Now;
                            descr           = "Zakończenie obsługi";
                        }
                        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_HandlingsExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #16
0
        public IHttpActionResult CreateStockTaking(string token, JDE_StockTakings 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;
                        if (item.TakingDate == null)
                        {
                            item.TakingDate = DateTime.Now;
                        }
                        db.JDE_StockTakings.Add(item);
                        db.SaveChanges();
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Inwentaryzacja 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. StockTakingId={StockTakingId}, UserId={UserId}", methodName, item.StockTakingId, UserId);
                        return(Ok(item));
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Błąd w {methodName}. StockTakingId={StockTakingId}, UserId={UserId}. Szczegóły: {Message}", methodName, item.StockTakingId, UserId, ex.ToString());
                        return(StatusCode(HttpStatusCode.InternalServerError));
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #17
0
        public IHttpActionResult DeletePart(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_Parts.Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.PartId == id);
                    if (items.Any())
                    {
                        string oFileName = items.FirstOrDefault().Image;
                        if (!string.IsNullOrEmpty(oFileName))
                        {
                            // There was a file, must delete it first
                            System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Files, oFileName));
                            System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Thumbs, oFileName));
                        }
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Usunięcie części", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault())
                        };
                        db.JDE_Parts.Remove(items.FirstOrDefault());
                        db.JDE_Logs.Add(Log);
                        db.SaveChanges();

                        return(Ok(items.FirstOrDefault()));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #18
0
        public static async Task CompleteProcessesHandlingsAsync(DbModel db, int ProcessId, int UserId, string reasonForClosure = null)
        {
            //it completes all open handlings for given process
            string descr = string.Empty;
            var    items = db.JDE_Handlings.AsNoTracking().Where(p => p.ProcessId == ProcessId && p.IsCompleted == false);
            var    User  = db.JDE_Users.AsNoTracking().Where(u => u.UserId == UserId).FirstOrDefault();

            if (items.Any())
            {
                foreach (var item in items)
                {
                    item.FinishedOn  = DateTime.Now;
                    item.IsActive    = false;
                    item.IsFrozen    = false;
                    item.IsCompleted = true;
                    if (reasonForClosure == null)
                    {
                        item.Output = $"Obsługa została zakończona przy zamykaniu zgłoszenia przez {User.Name + " " + User.Surname}";
                    }
                    else
                    {
                        item.Output = reasonForClosure;
                    }

                    descr = "Zakończenie obsługi";
                    JDE_Logs Log = new JDE_Logs {
                        UserId = UserId, Description = descr, TenantId = User.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 (Exception ex)
                {
                }
            }
        }
Exemple #19
0
        public IHttpActionResult EditAbandonReason(string token, int id, int UserId, JDE_AbandonReasons 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_AbandonReasons.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.AbandonReasonId == id);
                    if (items.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Edycja powodu niewykonania", 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_AbandonReasonExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #20
0
        public IHttpActionResult EditProcessAssign(string token, int id, int UserId, JDE_ProcessAssigns 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_ProcessAssigns.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.ProcessAssignId == id);
                    if (items.Any())
                    {
                        string descr = "Edycja przypisania zgłoszenia do użytkownika";
                        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_ProcessAssignsExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #21
0
 public IHttpActionResult CreateLog(string token, JDE_Logs item)
 {
     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;
             db.JDE_Logs.Add(item);
             db.SaveChanges();
             return(Ok(item));
             //return CreatedAtRoute("DefaultApi", new { id = item.ProcessId }, item);
         }
         else
         {
             return(NotFound());
         }
     }
     else
     {
         return(NotFound());
     }
 }
Exemple #22
0
        public IHttpActionResult EditUser(string token, int id, int UserId, JDE_Users jDE_Users)
        {
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    var users = db.JDE_Users.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.UserId == id);
                    if (users.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Edycja użytkownika", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(users.FirstOrDefault()), NewValue = new JavaScriptSerializer().Serialize(jDE_Users)
                        };
                        db.JDE_Logs.Add(Log);
                        db.Entry(jDE_Users).State = EntityState.Modified;

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!JDE_UsersExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #23
0
        public IHttpActionResult LogIn(string token, int id, JDE_Users jDE_Users)
        {
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    var users = db.JDE_Users.Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.UserId == id);
                    if (users.Any())
                    {
                        JDE_Logs Log = new JDE_Logs {
                            UserId = id, Description = "Logowanie", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now
                        };
                        jDE_Users.lastLoggedOn    = DateTime.Now;
                        db.Entry(jDE_Users).State = EntityState.Modified;
                        db.JDE_Logs.Add(Log);
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!JDE_UsersExists(id))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #24
0
 public IHttpActionResult CreateProcessAction(string token, JDE_ProcessActions item, int UserId)
 {
     Logger.Info("Start CreateProcessAction. UserId={UserId}", 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_ProcessActions.Add(item);
                 db.SaveChanges();
                 JDE_Logs Log = new JDE_Logs {
                     UserId = UserId, Description = "Utworzenie przypisania czynności do zgłoszenia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
                 };
                 db.JDE_Logs.Add(Log);
                 db.SaveChanges();
                 Logger.Info("Koniec CreateProcessAction. UserId={UserId}", UserId);
                 return(Ok(item));
             }catch (Exception ex)
             {
                 Logger.Error("Błąd w CreateProcessAction. UserId={UserId}. Szczegóły: {Message}", UserId, ex.ToString());
                 return(InternalServerError());
             }
         }
         else
         {
             return(NotFound());
         }
     }
     else
     {
         return(NotFound());
     }
 }
Exemple #25
0
 private void _DeleteFile(string token, string type, int UserId, int tenantId)
 {
     try
     {
         var items = db.JDE_Files.Where(f => f.Token == token);
         if (items.Any())
         {
             var assigns = db.JDE_FileAssigns.Where(fa => fa.FileId == items.FirstOrDefault().FileId);
             if (assigns.Any())
             {
                 //delete all assigns
                 foreach (var a in assigns)
                 {
                     db.JDE_FileAssigns.Remove(a);
                 }
             }
             JDE_Logs Log = new JDE_Logs {
                 UserId = UserId, Description = "Usunięcie pliku", TenantId = tenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault())
             };
             db.JDE_Files.Remove(items.FirstOrDefault());
             db.JDE_Logs.Add(Log);
             db.SaveChanges();
             //delete physical file
             if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(type))
             {
                 // There was a file, must delete it first
                 System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Files, $"{token}.{type}"));
                 System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Thumbs, $"{token}.{type}"));
             }
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemple #26
0
 public IHttpActionResult CreatePartUsage(string token, JDE_PartUsages item, int UserId)
 {
     Logger.Info("Start CreatePartUsage. PartId={PartId}, UserId={UserId}", 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_PartUsages.Add(item);
                 db.SaveChanges();
                 JDE_Logs Log = new JDE_Logs { UserId = UserId, Description = "Zużycie części", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item) };
                 db.JDE_Logs.Add(Log);
                 db.SaveChanges();
                 Logger.Info("CreatePartUsage: Zapis zakończony powodzeniem. PartId={PartId}, UserId={UserId}", item.PartId, UserId);
                 return Ok(item);
             }
             catch (Exception ex)
             {
                 Logger.Error("Błąd w CreatePartUsage. PartId={PartId}, UserId={UserId}. Szczegóły: {Message}", item.PartId, UserId, ex.ToString());
                 return StatusCode(HttpStatusCode.InternalServerError);
             }
         }
         else
         {
             return NotFound();
         }
     }
     else
     {
         return NotFound();
     }
 }
Exemple #27
0
        public IHttpActionResult CreateFile(string token, JDE_Files item, int UserId, int?PlaceId = null, int?PartId = null, int?ProcessId = null, int?UserLogId = null)
        {
            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;
                        item.CreatedBy = UserId;
                        item.Token     = Static.Utilities.GetToken();
                        db.JDE_Files.Add(item);
                        db.SaveChanges();
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Utworzenie pliku", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
                        };
                        db.JDE_Logs.Add(Log);
                        db.SaveChanges();

                        JDE_FileAssigns FileAssing = new JDE_FileAssigns {
                            FileId = item.FileId, CreatedBy = UserId, CreatedOn = DateTime.Now, TenantId = tenants.FirstOrDefault().TenantId, PartId = PartId, PlaceId = PlaceId, ProcessId = ProcessId, UserLogId = UserLogId
                        };
                        string word = "";
                        if (PlaceId != null)
                        {
                            word = "zasobu";
                        }
                        else if (PartId != null)
                        {
                            word = "części";
                        }
                        else if (ProcessId != null)
                        {
                            word = "zgłoszenia";
                        }
                        else
                        {
                            word = "logu użytkownika";
                        }
                        db.JDE_FileAssigns.Add(FileAssing);
                        db.SaveChanges();
                        JDE_Logs Log2 = new JDE_Logs {
                            UserId = UserId, Description = $"Przypisanie pliku do {word}", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
                        };
                        db.JDE_Logs.Add(Log2);
                        db.SaveChanges();
                        return(Ok(item));
                    }catch (Exception ex)
                    {
                        return(InternalServerError(ex));
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #28
0
        public HttpResponseMessage CreateFile(string token, string FileJson, int UserId, int?PlaceId = null, int?PartId = null, int?ProcessId = null, int?UserLogId = null)
        {
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    JavaScriptSerializer jss  = new JavaScriptSerializer();
                    JDE_Files            item = jss.Deserialize <JDE_Files>(FileJson);
                    var httpRequest           = HttpContext.Current.Request;

                    if (httpRequest.ContentLength > 0)
                    {
                        if (httpRequest.ContentLength > Static.RuntimeSettings.MaxFileContentLength)
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, $"{item.Name} przekracza dopuszczalną wielość pliku ({Static.RuntimeSettings.MaxFileContentLength} MB) i został odrzucony"));
                        }
                        if (string.IsNullOrEmpty(item.Token))
                        {
                            //create unique token unless the file already exists
                            item.Token    = Static.Utilities.GetToken();
                            item.TenantId = tenants.FirstOrDefault().TenantId;
                            var    postedFile = httpRequest.Files[0];
                            string filePath   = "";
                            if (postedFile != null && postedFile.ContentLength > 0)
                            {
                                var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));

                                filePath = $"{Static.RuntimeSettings.Path2Files}{item.Token +  ext.ToLower()}";

                                postedFile.SaveAs(filePath);
                                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, item);
                            }
                            item.CreatedOn = DateTime.Now;
                            item.CreatedBy = UserId;
                            item.Link      = filePath;
                            db.JDE_Files.Add(item);
                            db.SaveChanges();

                            JDE_Logs Log = new JDE_Logs {
                                UserId = UserId, Description = "Utworzenie pliku", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
                            };
                            db.JDE_Logs.Add(Log);
                            db.SaveChanges();
                        }
                    }

                    JDE_FileAssigns FileAssing = new JDE_FileAssigns {
                        FileId = item.FileId, CreatedBy = UserId, CreatedOn = DateTime.Now, TenantId = tenants.FirstOrDefault().TenantId, PartId = PartId, PlaceId = PlaceId, ProcessId = ProcessId, UserLogId = UserLogId
                    };
                    string word = "";
                    if (PlaceId != null)
                    {
                        word = "zasobu";
                    }
                    else if (PartId != null)
                    {
                        word = "części";
                    }
                    else if (ProcessId != null)
                    {
                        word = "zgłoszenia";
                    }
                    else
                    {
                        word = "logu użytkownika";
                    }
                    db.JDE_FileAssigns.Add(FileAssing);
                    db.SaveChanges();
                    JDE_Logs Log2 = new JDE_Logs {
                        UserId = UserId, Description = $"Przypisanie pliku do {word}", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, NewValue = new JavaScriptSerializer().Serialize(item)
                    };
                    db.JDE_Logs.Add(Log2);
                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, item));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
Exemple #29
0
        public IHttpActionResult CompleteUsersHandlings(string token, int UserId)
        {
            if (token != null && token.Length > 0)
            {
                var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                if (tenants.Any())
                {
                    string descr = string.Empty;
                    var    items = db.JDE_Handlings.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.UserId == UserId && u.IsCompleted == false);
                    if (items.Any())
                    {
                        foreach (var item in items)
                        {
                            //this has just been finished. Replace user's finish time with server time
                            item.FinishedOn  = DateTime.Now;
                            item.IsActive    = false;
                            item.IsFrozen    = false;
                            item.IsCompleted = true;
                            item.Output      = "Obsługa została zakończona automatycznie przy otwarciu kolejnej obsługi";
                            descr            = "Zakończenie obsługi";
                            var processes = db.JDE_Processes.AsNoTracking().Where(u => u.ProcessId == item.ProcessId && u.IsCompleted == false);
                            if (processes.Any())
                            {
                                //is the process of this handling completed? If not, put it on ice
                                //but only if there are no other open handlings for that process
                                var hands = db.JDE_Handlings.AsNoTracking().Where(u => u.ProcessId == processes.FirstOrDefault().ProcessId&& u.IsCompleted == false && u.HandlingId != item.HandlingId);
                                if (!hands.Any())
                                {
                                    var    process  = processes.FirstOrDefault();
                                    string OldValue = new JavaScriptSerializer().Serialize(process);
                                    process.IsFrozen        = true;
                                    process.LastStatus      = (int)ProcessStatus.Paused;
                                    process.LastStatusBy    = UserId;
                                    process.LastStatusOn    = DateTime.Now;
                                    db.Entry(process).State = EntityState.Modified;
                                    JDE_Logs Log2 = new JDE_Logs {
                                        UserId = UserId, Description = "Edycja zgłoszenia", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = OldValue, NewValue = new JavaScriptSerializer().Serialize(process)
                                    };
                                    db.JDE_Logs.Add(Log2);
                                }
                            }
                            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 (Exception ex)
                        {
                            return(StatusCode(HttpStatusCode.InternalServerError));
                        }
                    }
                }
            }

            return(Ok());
        }
Exemple #30
0
        public HttpResponseMessage EditPart(string token, int id, int UserId, string PartJson)
        {
            Logger.Info("EditPart. Start. PartJso={PartJson}", PartJson);
            try
            {
                if (token != null && token.Length > 0)
                {
                    var tenants = db.JDE_Tenants.Where(t => t.TenantToken == token.Trim());
                    if (tenants.Any())
                    {
                        JavaScriptSerializer jss  = new JavaScriptSerializer();
                        JDE_Parts            item = jss.Deserialize <JDE_Parts>(Uri.UnescapeDataString(PartJson));

                        try
                        {
                            var items = db.JDE_Parts.Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.PartId == id);
                            if (items.Any())
                            {
                                Logger.Info("EditPart: Znalazłem odpowiednią część. Przystępuję do edycji Id={id}, UserId={UserId}", id, UserId);
                                JDE_Parts orgItem = items.FirstOrDefault();

                                //handle image

                                var httpRequest = HttpContext.Current.Request;
                                if (httpRequest.ContentLength > 0)
                                {
                                    //there's a new content
                                    if (httpRequest.ContentLength > Static.RuntimeSettings.MaxFileContentLength)
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.BadRequest, $"{item.Name} przekracza dopuszczalną wielość pliku ({Static.RuntimeSettings.MaxFileContentLength} MB) i został odrzucony"));
                                    }

                                    item.TenantId = tenants.FirstOrDefault().TenantId;
                                    var    postedFile = httpRequest.Files[0];
                                    string filePath   = "";
                                    if (postedFile != null && postedFile.ContentLength > 0)
                                    {
                                        Logger.Info("EditPart: Znaleziono nowe pliki. Przystępuję do zapisu na dysku. Id={id}, UserId={UserId}", id, UserId);
                                        var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));

                                        filePath = $"{Static.RuntimeSettings.Path2Files}{item.Token + ext.ToLower()}";

                                        string oFileName = db.JDE_Parts.Where(p => p.PartId == id).FirstOrDefault().Image;
                                        if (!string.IsNullOrEmpty(oFileName))
                                        {
                                            // There was a file, must delete it first
                                            Logger.Info("EditPart: Istnieją poprzednie pliki pod tą nazwą. Przystępuję do usuwania. Id={id}, UserId={UserId}", id, UserId);
                                            System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Files, oFileName));
                                            System.IO.File.Delete(Path.Combine(RuntimeSettings.Path2Thumbs, oFileName));
                                        }

                                        postedFile.SaveAs(filePath);
                                        Logger.Info("EditPart: Zapisano pliki. Przystępuję do utworzenia miniatury.. Id={id}, UserId={UserId}", id, UserId);
                                        Static.Utilities.ProduceThumbnail(filePath);
                                        item.Image = item.Token + ext.ToLower();
                                    }
                                }

                                JDE_Logs Log = new JDE_Logs {
                                    UserId = UserId, Description = "Edycja części", TenantId = tenants.FirstOrDefault().TenantId, Timestamp = DateTime.Now, OldValue = new JavaScriptSerializer().Serialize(items.FirstOrDefault()), NewValue = PartJson
                                };
                                db.JDE_Logs.Add(Log);
                                item.LmBy = UserId;
                                item.LmOn = DateTime.Now;


                                try
                                {
                                    Logger.Info("EditPart: Przystępuję do zapisu zmian w bazie danych. Id={id}, UserId={UserId}", id, UserId);
                                    db.Entry(orgItem).CurrentValues.SetValues(item);
                                    db.Entry(orgItem).State = EntityState.Modified;
                                    db.SaveChanges();
                                    Logger.Info("EditPart: Zapisano zmiany w bazie. Id={id}, UserId={UserId}", id, UserId);
                                }
                                catch (DbUpdateConcurrencyException)
                                {
                                    if (!JDE_PartExists(id))
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                                    }
                                    else
                                    {
                                        throw;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Logger.Error("Błąd w EditPart. Id={id}, UserId={UserId}. Szczegóły: {Message}, nowa wartość: {item}", id, UserId, ex.ToString(), item);
                                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error("Błąd w EditPart. Id={id}, UserId={UserId}. Szczegóły: {Message}, nowa wartość: {item}", id, UserId, ex.ToString(), item);
                            return(Request.CreateResponse(HttpStatusCode.NoContent));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Błąd w EditPart. Id={id}, UserId={UserId}. Szczegóły: {Message}", id, UserId, ex.ToString());
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.ToString()));
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }