Example #1
0
        public async Task <IActionResult> Create(AddTesterParameter model)
        {
            if (ModelState.IsValid)
            {
                var isDeviceExists = _context.TesterParameters.Where(t => t.DeviceName.Equals(model.DeviceName)).Select(n => n.DeviceName).FirstOrDefault();
                if (isDeviceExists != null)
                {
                    ViewBag.DeviceAlreadyExists = "This device is already exists in the database";
                    return(View(model));
                }
                else
                {
                    var addedmodel = testerParametersRepository.Create(model);
                    _context.TesterParameters.Add(addedmodel);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Details), new { name = addedmodel.DeviceName }));
                }
            }
            return(View(model));
        }
        public TesterParameter Create(AddTesterParameter model)
        {
            var deviceParameters = $"<{TesterParameterCodeType.DeviceParameters}>" +
                $"{string.Join("", model.DeviceParameters.Parameters.Where(x => !string.IsNullOrWhiteSpace(x.Key)).Select(x => $"<{x.Key}>{x.Value}</{x.Key}>"))}" +
                $"</{TesterParameterCodeType.DeviceParameters}>";

            var firmwareGatesParameters = $"<{TesterParameterCodeType.FirmwareGates}>" +
                $"{string.Join("", model.FirmwareGates.Parameters.Where(x => !string.IsNullOrWhiteSpace(x.Key)).Select(x => $"<{x.Key}>{x.Value}</{x.Key}>"))}" +
                $"</{TesterParameterCodeType.FirmwareGates}>";

            var modemIncludeList = $"<{TesterParameterCodeType.ModemIncludeList}>" +
                $"{string.Join("", model.ModemIncludeList.Parameters.Where(x => !string.IsNullOrWhiteSpace(x.Key)).Select(x => $"<{x.Key}>{x.Value}</{x.Key}>"))}" +
                $"</{TesterParameterCodeType.ModemIncludeList}>";

            var testerParameter = new TesterParameter
            {
                DeviceName = model.DeviceName,
                Parameter = $"<ProductCode>{deviceParameters}{firmwareGatesParameters}{modemIncludeList}</ProductCode>",
                Revision = 1
            };
            return testerParameter;
        }