Example #1
0
        public ActionResult <BaseResponse> UpdateClassification(Classification classification)
        {
            try
            {
                _classificationService.AddOrUpdate(classification);

                if (classification.Id != 0)
                {
                    var oldClassification = _classificationService.Get(classification.Id);
                    var newClassification = _classificationService.Get(classification.Code);
                    _deviceService.UpdateClassifications(newClassification, oldClassification);
                }

                return(new BaseResponse()
                {
                    Message = $"Updated/Added classification: {classification.Model}"
                });
            }
            catch (Exception ex)
            {
                return(new BaseResponse()
                {
                    Error = ErrorCode.InternalError,
                    Message = ex.Message
                });
            }
        }
        public ActionResult <BaseResult <List <ClassificationViewModel> > > Get()
        {
            var result = _classificationService.Get();

            if (result.Success)
            {
                var resultMap = _mapper.Map <List <ClassificationViewModel> >(result.Data);

                return(BaseResult <List <ClassificationViewModel> > .OK(resultMap));
            }

            return(BaseResult <List <ClassificationViewModel> > .NotOK(result.Messages));
        }
Example #3
0
        public CustomerInputModel GetFilters()
        {
            var customer = new CustomerInputModel()
            {
                Cities          = _fieldService.GetDropDownList(_cityService.Get()),
                Classifications = _fieldService.GetDropDownList(_classificationService.Get()),
                Regions         = _fieldService.GetDropDownList(_regionService.Get()),
                Genders         = _fieldService.GetDropDownList(_genderService.Get()),
                Sellers         = _fieldService.GetDropDownList(_sellerService.Get())
            };

            return(customer);
        }
        private void ReadDevice(IExcelDataReader excel)
        {
            try
            {
                var devices = new List <Device>();

                while (excel.Read() && excel.GetString(3) != null)
                {
                    var device = new Device();

                    if (excel.GetValue(2) == null)
                    {
                        return;
                    }

                    string modelText = excel.GetValue(1)?.ToString();
                    if (string.IsNullOrEmpty(modelText))
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    var model = _deviceModelService.Get(modelText);

                    if (model == null)
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    device.Model = model;

                    string serialNumberText = excel.GetValue(2)?.ToString();
                    if (string.IsNullOrEmpty(serialNumberText))
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    device.SerialNumber = serialNumberText;

                    string ownedByText = excel.GetValue(3)?.ToString();
                    if (string.IsNullOrEmpty(ownedByText))
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    device.OwnedBy = _deviceLocationService.Get(ownedByText);

                    if (device.OwnedBy == null)
                    {
                        continue;
                    }

                    string dateText = excel.GetValue(4)?.ToString();
                    if (string.IsNullOrEmpty(dateText) || !DateTime.TryParse(dateText, out var acquisitionDate))
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    device.AcquisitionDate = acquisitionDate;

                    string statusText = excel.GetValue(5)?.ToString();
                    if (string.IsNullOrEmpty(statusText))
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    var status = _statusService.Get(statusText);

                    if (status == null)
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    device.Status = status;

                    string locationText = excel.GetValue(6)?.ToString();
                    if (string.IsNullOrEmpty(locationText))
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    var location = _deviceLocationService.Get(locationText);
                    if (location == null)
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    device.InitialLocation = location;

                    string groupText = excel.GetValue(7)?.ToString();
                    if (string.IsNullOrEmpty(groupText))
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    var group = _groupService.Get(groupText);
                    if (group == null)
                    {
                        //TODO HIGH Add Log
                        continue;
                    }
                    device.Classification = group;

                    string sfDate = excel.GetValue(8)?.ToString();
                    if (!string.IsNullOrEmpty(sfDate) && DateTime.TryParse(sfDate, out var parsedSfDate))
                    {
                        device.SfDate = parsedSfDate;
                    }

                    string sfNumber = excel.GetValue(9)?.ToString();
                    if (!string.IsNullOrEmpty(sfNumber))
                    {
                        device.SfNumber = sfNumber;
                    }

                    string notes = excel.GetValue(10)?.ToString();
                    if (!string.IsNullOrEmpty(notes))
                    {
                        device.AdditionalNotes = notes;
                    }
                    device.DeviceEvents = ReadEvents(excel);
                    devices.Add(device);
                }
                _deviceService.AddOrUpdate(devices);
            }
            catch (Exception ex)
            {
                //TODO: HIGH add logging
                throw new AdministrationException($"Failed to parse the device {excel.GetString(3)}");
            }
        }