public async Task <ActionResult> Index(CheckSerialNumberViewModels model) { string url = _appSettings.ApiUrl + "/Home/CheckSerialNumber"; client.BaseAddress = new Uri(url); SerialNumberDTO dto = new SerialNumberDTO() { SerialNumberInput = model.SerialNumberInput }; HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, dto); var responseData = new ResponseData <SerialNumberDTO>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <SerialNumberDTO> >().Result; if (responseData != null && responseData.Data != null) { ViewBag.SerialNumberExist = responseData.Data.SerialNumberExist; ViewBag.SerialNumberNotExist = responseData.Data.SerialNumberNotExist; return(View(model)); } } return(View()); }
public static SerialNumber ToModel(this SerialNumberDTO dto) { return(Mapper.Map <SerialNumber>(dto)); }
public async Task <ResponseData <SerialNumberDTO> > CheckSerialNumber([FromBody] SerialNumberDTO dto) { try { List <string> serialNumberExist = new List <string>(); List <string> serialNumberNotExist = new List <string>(); string[] lines = dto.SerialNumberInput.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (var item in lines) { var serialnumber = _applianceService.GetApplianceBySerialNumber(item); if (serialnumber != null && serialnumber.AccountId > 0) { var things = await TelitApi.ThingList(); Telit.ThingList.Result thing = new Telit.ThingList.Result(); if (things != null && things.things != null && things.things.success && things.things.@params != null && [email protected] != null && [email protected]() > 0) { foreach (var thingItem in [email protected]) { if (thingItem.key == serialnumber.SerialNumber) { serialNumberExist.Add(item); } } } } else { var things = await TelitApi.ThingList(); Telit.ThingList.Result thing = new Telit.ThingList.Result(); if (things != null && things.things != null && things.things.success && things.things.@params != null && [email protected] != null && [email protected]() > 0) { foreach (var thingItem in [email protected]) { if (thingItem.key == item) { serialNumberNotExist.Add(item); } } } } } dto.SerialNumberExist = serialNumberExist.ToArray <string>(); dto.SerialNumberNotExist = serialNumberNotExist.ToArray <string>(); var response = new ResponseData <SerialNumberDTO>(); response.Data = dto; response.Message = ResponseMessage.Success; response.Status = ResponseStatus.Success.ToString(); return(response); } catch (Exception ex) { var response = new ResponseData <SerialNumberDTO>(); response.Message = ex.Message; response.Status = ResponseStatus.Error.ToString(); return(response); } }