Exemplo n.º 1
0
        public IActionResult CreateRecord(CreateRecordModel model)
        {
            var board = _boards.GetEntity(model.BoardId);

            if (board == null)
            {
                return(RedirectToAction("Boards"));
            }
            if (ModelState.IsValid)
            {
                var column = board.Columns.FirstOrDefault(col => col.Id == model.ColumnId);
                var record = new Record
                {
                    Column = column,
                    Value  = model.Value.Trim()
                };
                _records.AddEntity(record);
                _records.Save();
            }
            else
            {
                ModelState.AddModelError("Name", "Missing name!");
            }
            return(RedirectToAction("Board", new { id = board.Id }));
        }
        public void UpdateDto(ItemBaseOnHardwareDto dto, string CurrentUser, int HardwareID)
        {
            ItemBaseOnHardware itemBaseOnHardware = new ItemBaseOnHardware();

            itemBaseOnHardware.ID   = dto.ID;
            itemBaseOnHardware.Name = dto.Name;
            if (dto.Status == "未测试")
            {
                itemBaseOnHardware.Status = 0;
            }
            else if (dto.Status == "正常")
            {
                itemBaseOnHardware.Status = 1;
            }
            else if (dto.Status == "异常")
            {
                itemBaseOnHardware.Status = 2;
            }
            itemBaseOnHardware.UpdateTime = DateTime.Now.ToString();
            itemBaseOnHardware.UpdateUser = CurrentUser;
            itemBaseOnHardware.Remark     = dto.Remark;
            itemBaseOnHardware.HardwareID = HardwareID;
            //判断是否修改
            var tem = _itemBaseOnHardwareRepository.GetEntityByIDNoTrack(dto.ID);                   //从数据库获取当前修改的对象

            if (tem.Status != itemBaseOnHardware.Status || tem.Remark != itemBaseOnHardware.Remark) //当界面发生更改,则更新ItemBaseOnHardware表并写入Record表中
            {
                _itemBaseOnHardwareRepository.UpdateEntity(itemBaseOnHardware);                     //更新到ItemBaseOnHardware表
                Record record = new Record();
                record.Status               = itemBaseOnHardware.Status;
                record.UpdateTime           = DateTime.Now.ToString();
                record.UpdateUser           = CurrentUser;
                record.Remark               = dto.Remark;
                record.ItemBaseOnHardwareID = itemBaseOnHardware.ID; //record的外键
                _recordRepository.AddEntity(record);                 //写入Record表
            }
        }