Пример #1
0
        public IHttpActionResult EditStorageBin(string token, int id, int UserId, JDE_StorageBins 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_StorageBins.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.StorageBinId == id);
                        if (items.Any())
                        {
                            Logger.Info("{methodName}: Znalazłem odpowiedni StorageBin. 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 regału", 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_StorageBinExists(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));
        }
Пример #2
0
        public HttpResponseMessage ArchiveStorageBin(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_StorageBins.AsNoTracking().Where(u => u.TenantId == tenants.FirstOrDefault().TenantId&& u.StorageBinId == id);
                    if (items.Any())
                    {
                        JDE_StorageBins orgItem = items.FirstOrDefault();

                        orgItem.IsArchived = true;
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Archiwizacja regału", 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_StorageBinExists(id))
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound));
                            }
                            else
                            {
                                throw;
                            }
                        }
                        catch (Exception ex)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
                        }
                    }
                }
            }
            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
Пример #3
0
        public IHttpActionResult CreateStorageBin(string token, JDE_StorageBins item, int UserId)
        {
            string methodName = System.Reflection.MethodInfo.GetCurrentMethod().Name;

            Logger.Info("Start {methodName}. Name={Name}, UserId={UserId}", methodName, item.Name, 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;
                        item.Token     = Static.Utilities.GetToken();
                        db.JDE_StorageBins.Add(item);
                        db.SaveChanges();
                        JDE_Logs Log = new JDE_Logs {
                            UserId = UserId, Description = "Utworzenie regału", 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. ID={ID}, UserId={UserId}", methodName, item.StorageBinId, UserId);
                        return(Ok(item));
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Błąd w {methodName}. ID={ID}, UserId={UserId}. Szczegóły: {Message}", methodName, item.StorageBinId, UserId, ex.ToString());
                        return(StatusCode(HttpStatusCode.InternalServerError));
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }