public ItemLogViewModel Map(ItemLog source, ItemLogViewModel destination)
        {
            if (source == null)
            {
                return null;
            }

            if (destination == null)
            {
                destination = new ItemLogViewModel();
            }

            if (source.Item != null)
            {
                destination.ItemId = source.Item.Id;
                destination.ItemName = source.Item.Name;
                destination.CreatedOn = source.Item.CreatedOn;
            }

            if (source.State != null)
            {
                destination.StateName = source.State.StateName;
            }

            destination.ModifiedOn = source.CreatedOn;
            destination.ModifiedBy = source.CreatedBy;

            return destination;

        }
        public void Save(Item item)
        {
            if (item == null || !item.States.Any())
            {
                return;
            }
            var itemLog = new ItemLog
                {
                    CreatedBy = PrincipalName,
                    CreatedOn = DateTime.Now,
                    Item = item,
                    State = item.States.FirstOrDefault()
                };

            try
            {
                    using (var transaction = new TransactionScope())
                    {
                        
                        repository.Save(itemLog);

                        repository.Commit();

                        transaction.Complete();

                }

            }
            catch (Exception ex)
            {
                throw new ItemException("Failed to save item log", ex);
            }
        }
        public static List <AuditLog> GetChangModifield(IEnumerable <EntityEntry> entities)
        {
            var modifiedEntities = entities
                                   .Where(p => p.State == EntityState.Modified).ToList();

            List <AuditLog> listLog = null;

            if (modifiedEntities.Count > 0)
            {
                listLog = new List <AuditLog>();
                foreach (var change in modifiedEntities)
                {
                    var entityName = change.Entity.GetType().Name;
                    var properties = change.OriginalValues.Properties;
                    if (properties.Count < 1)
                    {
                        break;
                    }
                    else
                    {
                        var primaryKey = properties.FirstOrDefault(x => x.IsKey());
                        //log.PropertyChange = new List<PropertyChange>();
                        PropertyChange propertyChange = null;
                        foreach (var prop in properties)
                        {
                            if (prop.Name == "UserModified" || prop.Name == "DatetimeModified" ||
                                prop.Name == "DatetimeCreated" || prop.Name == "UserCreated" ||
                                prop.Name == "ModifiedDate")
                            {
                                continue;
                            }
                            var originalValue = change.OriginalValues[prop] != null ? change.OriginalValues[prop].ToString() : string.Empty;
                            var currentValue  = change.CurrentValues[prop] != null ? change.CurrentValues[prop].ToString() : string.Empty;
                            //if (prop.Name == "InactiveOn" && change.OriginalValues["Inactive"].ToString() == change.OriginalValues["Inactive"].ToString()) continue;
                            if (originalValue != currentValue)
                            {
                                var addObject = new PropertyChange()
                                {
                                    PropertyName = prop.Name,
                                    OldValue     = originalValue,
                                    NewValue     = currentValue
                                };
                                propertyChange = addObject;
                            }
                        }
                        if (propertyChange != null)
                        {
                            var log = new ItemLog {
                                Id = Guid.NewGuid()
                            };
                            log.PropertyCommon = new PropertyCommon
                            {
                                PrimaryKeyValue  = change.OriginalValues[primaryKey.Name].ToString(),
                                ActionType       = EntityState.Modified,
                                DatetimeModified = DateTime.Now,
                                UserModified     = change.CurrentValues["UserModified"]?.ToString()
                            };
                            log.NewObject = change.Entity;
                            log.PropertyCommon.PropertyChange = propertyChange;
                            var objectLog = new AuditLog {
                                EntityName = entityName, ChangeLog = log
                            };
                            listLog.Add(objectLog);
                        }
                    }
                }
            }
            return(listLog);
        }
示例#4
0
        public IActionResult SaveItemLocation(ItemListViewModel[] list, string LocationName)
        {
            string status  = "";
            string message = "";

            try
            {
                foreach (var item in list)
                {
                    LocationItemDetail loc = new LocationItemDetail
                    {
                        CreatedDate = DateTime.Now,
                        Equipment   = item.Equipment,
                        HeaderId    = item.HeaderId,
                        ItemId      = item.ItemId,
                        UpdatedBy   = User.Identity.GetFullName()
                    };
                    _context.Add(loc);

                    ItemLog itemLog = new ItemLog
                    {
                        ItemId      = item.ItemId,
                        OldStatus   = "",
                        NewStatus   = "",
                        CreatedDate = DateTime.Now,
                        CreatedBy   = User.Identity.GetFullName(),
                        Description = "Added item to location " + LocationName
                    };

                    _context.Items.Find(item.ItemId).IsIn = 0;

                    _context.Add(itemLog);
                }

                Log log = new Log
                {
                    Descriptions = "Added items in [LocationItemDetail] HeaderId : " + list[0].HeaderId,
                    Action       = "Add",
                    Status       = "Success",
                    UserId       = User.Identity.GetUserName(),
                    CreatedDate  = DateTime.Now
                };
                _context.Add(log);

                _context.SaveChanges();



                status = "success";
            }
            catch (Exception e)
            {
                message = e.Message;
                status  = "fail";
            }

            var model = new
            {
                status,
                message
            };

            return(Json(model));
        }
示例#5
0
        public async Task <IActionResult> Edit(int id, Item item, string StatusOldValue, int CompanyId)
        {
            //int companyAccess = Convert.ToInt32(User.Identity.GetCompanyAccess());//disabled 01032022
            int companyAccess = CompanyId;


            if (id != item.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    item.Status = "Active";
                    _context.Update(item);
                    await _context.SaveChangesAsync();


                    if (item.ItemStatus != StatusOldValue)
                    {
                        ItemLog itemLog = new ItemLog
                        {
                            ItemId      = item.Id,
                            OldStatus   = StatusOldValue,
                            NewStatus   = item.ItemStatus,
                            CreatedDate = DateTime.Now,
                            CreatedBy   = User.Identity.GetFullName(),
                            Description = "Changes status from " + StatusOldValue + " to " + item.ItemStatus
                        };
                        _context.Add(itemLog);
                    }


                    Log log = new Log
                    {
                        Descriptions = "Update Item - " + item.Id,
                        Action       = "Edit",
                        Status       = "success",
                        UserId       = User.Identity.GetUserName()
                    };
                    _context.Add(log);

                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemExists(item.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(item));
        }
示例#6
0
        public async Task <IActionResult> Create(ItemViewModel item)
        {
            if (item.DatePurchased == null)
            {
                item.Warranty = 0;
            }
            if (ModelState.IsValid)
            {
                //int companyAccess = Convert.ToInt32(User.Identity.GetCompanyAccess());//disabled 01032022
                int    companyAccess = item.CompanyId;
                string series        = "";
                string refno         = "";
                string st            = "";

                string series_code = "";

                if (companyAccess == 1)
                {
                    series_code = "ITEMSLPGC";
                    st          = "SLIT";
                }
                if (companyAccess == 2)
                {
                    series_code = "ITEMSCPC";
                    st          = "SCIT";
                }


                series = new NoSeriesController(_context).GetNoSeries(series_code);

                refno = st + series;



                item.Code = refno;
                Item _item = new Item {
                    Code = item.Code,

                    Name = item.Name,

                    SerialNo = item.SerialNo,

                    DatePurchased = item.DatePurchased,

                    Warranty = item.Warranty,

                    ItemStatus = item.ItemStatus,

                    Status = "Active",

                    EquipmentType = item.EquipmentType,

                    IsIn = 1,

                    Type = item.Type,

                    Capacity = item.Capacity
                };

                _context.Add(_item);
                await _context.SaveChangesAsync();


                string x = new NoSeriesController(_context).UpdateNoSeries(series, series_code);


                ItemLog itemLog = new ItemLog
                {
                    ItemId      = item.Id,
                    OldStatus   = "",
                    NewStatus   = "New",
                    CreatedDate = DateTime.Now,
                    CreatedBy   = User.Identity.GetFullName(),
                    Description = "Item added to item maintenance"
                };
                _context.Add(itemLog);


                Log log = new Log
                {
                    Descriptions = "Create Item - " + item.Id,
                    Action       = "Create",
                    Status       = "success",
                    UserId       = User.Identity.GetUserName()
                };
                _context.Add(log);
                _context.SaveChanges();



                return(RedirectToAction(nameof(Index)));
            }
            return(View(item));
        }
示例#7
0
 public void Create(ItemLog itemLog)
 {
     _context.ItemLog.Add(itemLog);
 }
示例#8
0
 public void Add(ItemLog itemLog)
 {
     _context.ItemLog.Add(itemLog);
 }
示例#9
0
        public async Task <IActionResult> MoveItem(int id, string StorageName, string UserName)
        {
            var Temp = await _db.Items.FirstOrDefaultAsync(a => a.ItemID == id);

            if (Temp.ItemProtect == true && StorageName == "Автозавод")
            {
                return(Json(new
                {
                    success = false,
                    message = "Ошибка! Позиция только для собственной формовки."
                }));
            }

            else
            {
                if (!(Temp.ItemStorageID == "Архив"))
                {
                    if (StorageName != Temp.ItemStorageID)
                    {
                        ItemLog log = new ItemLog()
                        {
                            LogItemName     = Temp.ItemName,
                            LogItemArticle  = Temp.ItemArticle,
                            LogUserName     = UserName,
                            LogOldStorage   = Temp.ItemStorageID,
                            LogCurStorage   = StorageName,
                            LogDateTransfer = DateTime.Now
                        };

                        await _db.ItemLogs.AddAsync(log);

                        Temp.ItemStorageID    = StorageName;
                        Temp.DateTransferItem = DateTime.Now;

                        if (Temp == null)
                        {
                            return(Json(new { success = false, message = "Ошибка перемещения" }));
                        }
                        await _db.SaveChangesAsync();

                        return(Json(new
                        {
                            success = true,
                            message = "Успешное перемещение"
                        }));
                    }
                    else
                    {
                        return(Json(new
                        {
                            success = false,
                            message = "Невозможно переместить матрицу на один и тот же склад"
                        }));
                    }
                }
                else
                {
                    return(Json(new
                    {
                        success = false,
                        message = "Только администратор системы может перемещать матрицы из архива."
                    }));
                }
            }
        }
示例#10
0
 public ModuleExecution(ObjectResolver objectResolver, RunLog runLog, ItemLog parentItemLog)
 {
     this.objectResolver = objectResolver;
     this.runLog         = runLog;
     this.parentItemLog  = parentItemLog;
 }
示例#11
0
 /// <summary>
 /// Creates an instance of this DTO From an ItemLog.
 /// </summary>
 /// <param name="log">ItemLog instance</param>
 /// <returns>DTO with the data from the log</returns>
 public static LogDTO FromItemLog(ItemLog log)
 {
     return(new LogDTO {
         Name = log.Item.Name, Amount = log.Count, Time = log.Time, Type = LogType.Item.ToString().ToLower()
     });
 }
示例#12
0
 public void SetItemLog(ItemLog itemLog)
 {
     this.DataContext = itemLog;
 }