/// <summary>
 /// Creates a new machine.
 /// </summary>
 /// <remarks>
 /// Required permissions: Machines.Create.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='machineDto'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <MachineDto> PostAsync(this IMachines operations, MachineDto machineDto, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.PostWithHttpMessagesAsync(machineDto, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #2
0
        public async Task <IActionResult> EditMachine(int id, [FromForm] MachineDto machineDto)
        {
            //try
            //{
            //  using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
            //{
            if (!ModelState.IsValid)
            {
                var category = await _categoryRepository.GetCategories();

                return(View(new MachineCreateUpdateViewModel
                {
                    Categories = category,
                    MachineDto = machineDto
                }));
            }
            var machine = _mapper.Map <MachineDto, Machine>(machineDto);

            machine.Id = id;

            _machineRepository.UpdateMachine(machine);
            await _unitOfWork.CompleteAsync();

            return(RedirectToAction("ManageMachines"));
            // tran.Complete();
        }
Пример #3
0
        public IActionResult UpdateMachine(MachineDto machineDto)
        {
            var machine = _mapper.Map <Machine>(machineDto);

            _repo.Edit(machine);
            return(Ok(machineDto));
        }
Пример #4
0
        public async Task <IActionResult> PutMachine(Guid id, MachineDto machine)
        {
            if (id != machine.MachineId)
            {
                return(BadRequest());
            }
            //TODO: Update this
            _context.Entry(machine).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MachineExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }
Пример #5
0
 /// <summary>
 /// Creates a new machine.
 /// </summary>
 /// <remarks>
 /// Client Credentials Flow required permissions: Machines or Machines.Write.
 ///
 /// Required permissions: Machines.Create.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <MachineDto> PostAsync(this IMachines operations, MachineDto body = default(MachineDto), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PostWithHttpMessagesAsync(body, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        public static void Update(this Machine machine, MachineDto dto)
        {
            machine.Name = dto.Name;

            machine.FriendlyName = dto.FriendlyName;

            machine.CredentialsId = dto.CredentialsId;
        }
        public bool DeleteMachine(int id)
        {
            var machine = new MachineDto {
                Id = id
            };

            return(_machineManager.DeleteMachine(machine));
        }
Пример #8
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(cbMachine.Text))
            {
                MessageBox.Show("Код станка не может быть пустым.", "Проверка");
                return;
            }

            if (string.IsNullOrEmpty(cbTypeRepair.Text))
            {
                MessageBox.Show("Тип ремонта не может быть пустым.", "Проверка");
                return;
            }

            if (string.IsNullOrEmpty(dpStartDate.Text))
            {
                MessageBox.Show("Укажите дату начала ремонта", "Проверка");
                return;
            }
            if (tmNote.Text.Length > 500)
            {
                MessageBox.Show("Примечание не может содержать более 500 символов.", "Проверка");
            }

            RepairDto mach = new RepairDto();

            mach.StartDate   = Convert.ToDateTime((this.dpStartDate.Text));
            mach.CodeMachine = Convert.ToInt32(this.cbMachine.Text);
            mach.IDRepair    = this.cbTypeRepair.SelectedItem as NameRepairDto;
            mach.Note        = this.tmNote.Text;

            MachineDto m  = new MachineDto();
            MachineDao mD = new MachineDao();
            Machine    MM = mD.Get(Convert.ToInt32(this.cbMachine.Text));

            m.CodeMashine    = Convert.ToInt32(this.cbMachine.Text);
            m.NumberOfRepair = MM.NumberOfRepair + 1;
            m.IDCountry      = DtoConvert.Convert(DaoFactory.GetCountryDao().Get(MM.IDCountry));
            m.IDEnterprise   = DtoConvert.Convert(DaoFactory.GetEnterprisenDao().Get(MM.IDEnterprise));
            IMachineProcess mP          = ProcessFactory.GetMachinerProcess();
            IRepairProcess  machProcess = ProcessFactory.GetRepairProcess();

            if (_id.ToString().Equals("01-01-0001 0:00:00"))
            {
                machProcess.Add(mach);
                machineGet = ProcessFactory.GetMachinerProcess().GetList();
                mP.Update(m);
            }
            else
            {
                mach.StartDate = _id;
                machProcess.Update(mach);
            }



            this.Close();
        }
Пример #9
0
        public static Machine Convert(MachineDto machineDto)
        {
            if (machineDto == null)
            {
                return(null);
            }
            Machine machine = new Machine();

            machine.CodeMashine    = machineDto.CodeMashine;
            machine.IDCountry      = machineDto.IDCountry.IDCountry;
            machine.IDEnterprise   = machineDto.IDEnterprise.IDEnterprise;
            machine.NumberOfRepair = machineDto.NumberOfRepair;
            return(machine);
        }
Пример #10
0
        public ActionResult Edit(MachineDto Machinedto)
        {
            ResultJsonInfo resultJsonInfo = new ResultJsonInfo()
            {
                Data = "", ErrorMsg = "", Success = true
            };

            if (Machinedto != null)
            {
                Machinedto.UpdateUser = ServiceHelper.GetCurrentUser().UserName;
                Machinedto.UpdateTime = DateTime.Now;
            }
            return(Json(new { resultJsonInfo }, JsonRequestBehavior.AllowGet));
        }
Пример #11
0
        public ActionResult Add(MachineDto Machinedto)
        {
            ResultJsonInfo resultJsonInfo = new ResultJsonInfo()
            {
                Data = "", ErrorMsg = "", Success = true
            };

            if (Machinedto != null)
            {
                Machinedto.CreateUser  = ServiceHelper.GetCurrentUser().UserName;
                Machinedto.CredateTime = DateTime.Now;
            }
            return(this.Ajax_JGClose());
        }
Пример #12
0
        [HttpPost("agregar")] // metodo POST para agregar elementos
        public IActionResult Insert([FromBody] MachineDto machineDto)
        {
            var machine = _mapper.Map <Machine>(machineDto);  // Mapear dto a entitidad

            try
            {
                machine    = _machineRepository.Insert(machine); // Guardamos el elemento
                machineDto = _mapper.Map <MachineDto>(machine);  // Mapear entitidad a dto
                return(Ok(machineDto));
            }
            catch (AppException ex)                               // Si ocurre un error...
            {
                return(BadRequest(new { message = ex.Message })); // Retornar mensaje de error
            }
        }
Пример #13
0
        [HttpPut("actualizar")] // metodo PUT para actualizar elemento
        public IActionResult Update([FromBody] MachineDto machineDto)
        {
            var machine = _mapper.Map <Machine>(machineDto); // Mapear dto a entitidad

            try
            {
                machine    = _machineRepository.Update(machineDto); // Actualizamos el elemento
                machineDto = _mapper.Map <MachineDto>(machine);     // Mapear entitidad a dto
                return(Ok(machineDto));
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message })); // Retornar mensaje de error
            }
        }
Пример #14
0
        public async Task <ActionResult <MachineDto> > PostMachine(MachineDto machine)
        {
            var machineMapped = new Machine
            {
                Identifier = machine.Identifier,
                Model      = machine.Model,
                Brand      = machine.Brand
            };
            await _context.Machines.AddAsync(machineMapped);

            await _context.SaveChangesAsync();

            machine.MachineId = machineMapped.MachineId;
            return(CreatedAtAction("GetMachine", new { id = machineMapped.MachineId }, machine));
        }
Пример #15
0
        public void SaveMachineData(MachineDto machine)
        {
            var existedMachine = _context.Machine.FirstOrDefault(m => m.MachineId == machine.MachineId);

            if (existedMachine != null)
            {
                existedMachine = _mapper.Map(machine, existedMachine);
            }
            else
            {
                _context.Machine.Add(_mapper.Map <Machine>(machine));
            }

            _context.SaveChanges();
        }
Пример #16
0
        public static MachineDto Convert(Machine machine)
        {
            if (machine == null)
            {
                return(null);
            }
            MachineDto machineDto = new MachineDto();

            machineDto.CodeMashine = machine.CodeMashine;
            machineDto.IDCountry   = Convert(DaoFactory.GetCountryDao().Get(machine.IDCountry));

            machineDto.IDEnterprise   = Convert(DaoFactory.GetEnterprisenDao().Get(machine.IDEnterprise));
            machineDto.NumberOfRepair = machine.NumberOfRepair;

            return(machineDto);
        }
Пример #17
0
        private void btnEditM_Click(object sender, RoutedEventArgs e)
        {
            MachineDto item = dgMachine.SelectedItem as MachineDto;

            if (item == null)
            {
                MessageBox.Show("Выберите запись для редактирования", "Редактирование");
                return;
            }

            WinMachine window = new WinMachine();

            window.Load(item);
            window.ShowDialog();
            btnUpdateM_Click(sender, e);
        }
Пример #18
0
        public IActionResult AddMachine(MachineDto machineDto)
        {
            machineDto.UserId = Convert.ToInt32(this.User.FindFirstValue(ClaimTypes.NameIdentifier));
            var machine = _mapper.Map <Machine>(machineDto);

            if (machineDto.Id > 0)
            {
                _repo.Edit(machine);
                return(Ok(machineDto));
            }
            else
            {
                _repo.Add <Machine>(machine);
                var newMachineDto = _mapper.Map <MachineDto>(machine);
                return(Ok(newMachineDto));
            }
        }
Пример #19
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(cbCodeMachine.Text))
            {
                MessageBox.Show("Код станка не может быть пустым.", "Проверка");
                return;
            }

            if (string.IsNullOrEmpty(cbEnterprise.Text))
            {
                MessageBox.Show("Название предприятия не может быть пустым.", "Проверка");
                return;
            }

            if (string.IsNullOrEmpty(cbCountry.Text))
            {
                MessageBox.Show("Название страны не может быть пустым.", "Проверка");
                return;
            }


            MachineDto mach = new MachineDto();

            mach.CodeMashine    = Convert.ToInt32(this.cbCodeMachine.Text);
            mach.IDCountry      = cbCountry.SelectedItem as CountryDto;
            mach.IDEnterprise   = cbEnterprise.SelectedItem as EnterpriseDto;
            mach.NumberOfRepair = numbRep;



            IMachineProcess machProcess = ProcessFactory.GetMachinerProcess();

            if (_id == 0)
            {
                mach.NumberOfRepair = 0;
                machProcess.Add(mach);
            }
            else
            {
                mach.CodeMashine = _id;
                machProcess.Update(mach);
            }

            this.Close();
        }
Пример #20
0
        // Actualizar elemento
        public Machine Update(MachineDto machineParam)
        {
            // Buscamos elemento a modificar
            var machine = _context.Machine.Find(machineParam.idMachine);

            // verificamos q existe
            if (machine == null)
            {
                throw new AppException("Maquina no existe.");
            }

            // actualizamos dato
            machine.update(machineParam, _context);

            // Guardar cambios
            _context.Machine.Update(machine);
            _context.SaveChanges();
            return(machine);
        }
Пример #21
0
        public async Task <IActionResult> AddMachine(MachineDto machineDto)
        {
            if (!ModelState.IsValid)
            {
                var category = await _categoryRepository.GetCategories();

                return(View(new MachineCreateUpdateViewModel
                {
                    MachineDto = machineDto,
                    Categories = category
                }));
            }
            var machine = _mapper.Map <MachineDto, Machine>(machineDto);
            await _machineRepository.AddMachineAsync(machine);

            await _unitOfWork.CompleteAsync();

            return(RedirectToAction("ManageMachines"));
        }
Пример #22
0
        private void btnDeleteM_Click(object sender, RoutedEventArgs e)
        {
            MachineDto item = dgMachine.SelectedItem as MachineDto;

            if (item == null)
            {
                MessageBox.Show("Выберите запись для удаления", "Удаление станка");
                return;
            }

            MessageBoxResult result = MessageBox.Show("Удалить станок " + item.CodeMashine + "?", "Удаление станка", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }

            ProcessFactory.GetMachinerProcess().Delete(item.CodeMashine);

            btnUpdateM_Click(sender, e);
        }
Пример #23
0
        public void Load(MachineDto mach)
        {
            if (mach == null)
            {
                return;
            }

            this._id = mach.CodeMashine;
            numbRep  = mach.NumberOfRepair;

            foreach (CountryDto countr in countryGet)
            {
                if (countr.IDCountry == mach.IDCountry.IDCountry)
                {
                    this.cbCountry.SelectedItem = countr;
                    break;
                }
            }

            foreach (EnterpriseDto enter in enterpriseGet)
            {
                if (mach.IDEnterprise.IDEnterprise == enter.IDEnterprise)
                {
                    this.cbEnterprise.SelectedItem = enter;
                    break;
                }
            }

            foreach (TypeMachineDto mac in Machine)
            {
                if (mach.CodeMashine == mac.CodeMachine)
                {
                    this.cbCodeMachine.SelectedItem = mac;
                    break;
                }
            }

            cbCodeMachine.IsEnabled = false;
        }
Пример #24
0
        public void fillExcelTableByType(IEnumerable <object> grid, string status, FileInfo xlsxFile)
        {
            try
            {
                if (grid != null)
                {
                    ExcelPackage pck   = new ExcelPackage(xlsxFile);
                    var          excel = pck.Workbook.Worksheets.Add(status);
                    int          x     = 1;
                    int          y     = 1;

                    CultureInfo cultureInfo = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
                    Thread.CurrentThread.CurrentCulture             = cultureInfo;
                    cultureInfo.NumberFormat.NumberDecimalSeparator = ".";
                    excel.Cells["A1:Z1"].Style.Font.Bold            = true;
                    excel.Cells.Style.HorizontalAlignment           = ExcelHorizontalAlignment.Left;
                    excel.Cells.Style.Numberformat.Format           = "General";

                    Object dtObj = new Object();

                    switch (status)
                    {
                    case "Country": dtObj = new CountryDto(); break;

                    case "Enterprise": dtObj = new EnterpriseDto(); break;

                    case "Repair": dtObj = new RepairDto(); break;

                    case "Machine": dtObj = new MachineDto(); break;

                    case "TypeMachine": dtObj = new TypeMachineDto(); break;

                    case "TypeRepair": dtObj = new TypeRepairDto(); break;
                    }
                    foreach (var prop in dtObj.GetType().GetProperties())
                    {
                        excel.Cells[y, x].Value = prop.Name.Trim();
                        x++;
                    }
                    foreach (var item in grid)
                    {
                        y++;
                        Object itemObj = item;
                        x = 1;
                        foreach (var prop in itemObj.GetType().GetProperties())
                        {
                            object t = prop.GetValue(itemObj, null);
                            object val;

                            if (t == null)
                            {
                                val = "";
                            }
                            else
                            {
                                val = t.ToString();
                                if (t is CountryDto)
                                {
                                    val = ((CountryDto)t).NameCountry;
                                }

                                if (t is MachineDto)
                                {
                                    val = ((MachineDto)t).CodeMashine;
                                }

                                if (t is RepairDto)
                                {
                                    val = ((RepairDto)t).StartDate;
                                }

                                if (t is EnterpriseDto)
                                {
                                    val = ((EnterpriseDto)t).NameEnterprise;
                                }

                                if (t is TypeMachineDto)
                                {
                                    val = ((TypeMachineDto)t).CodeMachine;
                                }

                                if (t is TypeRepairDto)
                                {
                                    val = ((TypeRepairDto)t).NameRepair;
                                }

                                if (t is NameRepairDto)
                                {
                                    val = ((NameRepairDto)t).NameTypeRepair;
                                }
                            }
                            excel.Cells[y, x].Value = val;
                            x++;
                        }
                    }
                    excel.Cells.AutoFitColumns();
                    pck.Save();
                }
                else
                {
                    MessageBox.Show("Данные не загружены!");
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Ошибка");
            }
        }
 /// <summary>
 /// Partially updates a machine.
 /// </summary>
 /// <remarks>
 /// Required permissions: Machines.Edit.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// key: Id
 /// </param>
 /// <param name='machineDto'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task PatchByIdAsync(this IMachines operations, long id, MachineDto machineDto, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     (await operations.PatchByIdWithHttpMessagesAsync(id, machineDto, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
 /// <summary>
 /// Partially updates a machine.
 /// </summary>
 /// <remarks>
 /// Required permissions: Machines.Edit.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// key: Id
 /// </param>
 /// <param name='machineDto'>
 /// </param>
 public static void PatchById(this IMachines operations, long id, MachineDto machineDto)
 {
     operations.PatchByIdAsync(id, machineDto).GetAwaiter().GetResult();
 }
 /// <summary>
 /// Edits a machine based on its key.
 /// </summary>
 /// <remarks>
 /// Required permissions: Machines.Edit.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// key: Id
 /// </param>
 /// <param name='machineDto'>
 /// </param>
 public static MachineDto PutById(this IMachines operations, long id, MachineDto machineDto)
 {
     return(operations.PutByIdAsync(id, machineDto).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Creates a new machine.
 /// </summary>
 /// <remarks>
 /// Required permissions: Machines.Create.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='machineDto'>
 /// </param>
 public static MachineDto Post(this IMachines operations, MachineDto machineDto)
 {
     return(operations.PostAsync(machineDto).GetAwaiter().GetResult());
 }
Пример #29
0
 /// <summary>
 /// Partially updates a machine.
 /// </summary>
 /// <remarks>
 /// Client Credentials Flow required permissions: Machines or Machines.Write.
 ///
 /// Required permissions: Machines.Edit.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='key'>
 /// </param>
 /// <param name='body'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task PatchByIdAsync(this IMachines operations, long key, MachineDto body = default(MachineDto), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.PatchByIdWithHttpMessagesAsync(key, body, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
Пример #30
0
 /// <summary>
 /// Partially updates a machine.
 /// </summary>
 /// <remarks>
 /// Client Credentials Flow required permissions: Machines or Machines.Write.
 ///
 /// Required permissions: Machines.Edit.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='key'>
 /// </param>
 /// <param name='body'>
 /// </param>
 public static void PatchById(this IMachines operations, long key, MachineDto body = default(MachineDto))
 {
     operations.PatchByIdAsync(key, body).GetAwaiter().GetResult();
 }