Esempio n. 1
0
        public async Task <IActionResult> DeactivateAssignee(int id)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            var a = await _repo.GetAssignee(id);

            if (a == null)
            {
                return(BadRequest($"Assignee {id} could not be found"));
            }

            a.Active       = 0;
            a.ModifiedBy   = User.Identity.Name.Replace("\\\\", "\\");
            a.ModifiedDate = DateTime.Now;

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Failed to delete assignee"));
        }
        public async Task <IActionResult> DeactivateDeviceDate(int id)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            var dd = await _repo.GetDeviceDate(id);

            if (dd == null)
            {
                return(BadRequest($"Device Date {id} could not be found"));
            }

            dd.Active       = 0;
            dd.ModifiedBy   = User.Identity.Name.Replace("\\\\", "\\");
            dd.ModifiedDate = DateTime.Now;

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Failed to delete device date"));
        }
Esempio n. 3
0
        public async Task <IActionResult> AddSimCard([FromBody] SimCardSaveResource simCardSaveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /* Test for prexistence */
            var filter = new MdaSimCardQuery()
            {
                Iccid       = simCardSaveResource.Iccid,
                PhoneNumber = simCardSaveResource.PhoneNumber,
                Carrier     = simCardSaveResource.Carrier
            };
            var simCardFromRepo = await _repo.GetSimCards(filter);

            if (simCardFromRepo.Any())
            {
                return(BadRequest($"Sim Card with ICCID {simCardSaveResource.Iccid} already exists"));
            }

            var simCard = _mapper.Map <MdaSimCard>(simCardSaveResource);

            simCard.CreatedBy = User.Identity.Name;

            _repo.Add(simCard);

            if (await _repo.SaveAll())
            {
                return(Ok(simCard));
            }

            return(BadRequest("Failed to add Sim Card"));
        }
Esempio n. 4
0
        public async Task <IActionResult> AddProductModel([FromBody] ProductModelSaveResource saveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var filter = new MdaProductModelQuery()
            {
                ProductManufacturerId = saveResource.ProductManufacturerId,
                ProductTypeId         = saveResource.ProductTypeId,
                Name = saveResource.Name
            };

            var productModelFromRepo = await _repo.GetProductModels(filter);

            if (productModelFromRepo.Any())
            {
                return(BadRequest($"Product Model {saveResource.Name} already exists for specified type and manufacturer."));
            }

            var productModel = _mapper.Map <MdaProductModel>(saveResource);

            productModel.CreatedBy = User.Identity.Name;

            _repo.Add(productModel);

            if (await _repo.SaveAll())
            {
                return(Ok(productModel));
            }

            return(BadRequest("Failed to add product model"));
        }
Esempio n. 5
0
        public async Task <IActionResult> AddProduct([FromBody] ProductSaveResource saveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /* Pre-existence Test */
            var filter = new MdaProductQuery()
            {
                PartNum = saveResource.PartNum,
                Active  = 2
            };

            var productFromRepo = await _repo.GetProducts(filter);

            if (productFromRepo.Any())
            {
                return(BadRequest($"Product with Part Number {saveResource.PartNum} already exists."));
            }

            var product = _mapper.Map <MdaProduct>(saveResource);

            product.CreatedBy = User.Identity.Name;

            _repo.Add(product);

            if (await _repo.SaveAll())
            {
                return(Ok(product));
            }

            return(BadRequest("Failed to add product"));
        }
Esempio n. 6
0
        public async Task <IActionResult> AddProductCapacity([FromBody] ProductCapacitySaveResource saveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var filter = new MdaProductCapacityQuery()
            {
                Name           = saveResource.Name,
                ProductModelId = saveResource.ProductModelId
            };

            var productCapacityFromRepo = await _repo.GetProductCapacities(filter);

            if (productCapacityFromRepo.Any())
            {
                return(BadRequest($"Product Capacity {saveResource.Name} already exists for the specified model."));
            }

            var productCapacity = _mapper.Map <MdaProductCapacity>(saveResource);

            productCapacity.CreatedBy = User.Identity.Name;

            _repo.Add(productCapacity);

            if (await _repo.SaveAll())
            {
                return(Ok(productCapacity));
            }

            return(BadRequest("Failed to add product capacity."));
        }
        public async Task <IActionResult> AddDeviceStatus([FromBody] DeviceStatusSaveResource deviceStatusSaveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /* Prexistence Test */
            var filter = new MdaDeviceStatusQuery()
            {
                Name = deviceStatusSaveResource.Name
            };
            var deviceStatusFromRepo = await _repo.GetDeviceStatuses(filter);

            if (deviceStatusFromRepo.Any())
            {
                return(BadRequest($"Device Status {deviceStatusSaveResource.Name} already exists."));
            }

            var deviceStatus = _mapper.Map <MdaDeviceStatus>(deviceStatusSaveResource);

            deviceStatus.CreatedBy = User.Identity.Name;

            _repo.Add(deviceStatus);

            if (await _repo.SaveAll())
            {
                return(Ok(deviceStatus));
            }

            return(BadRequest("Failed to add device status"));
        }
        public async Task <IActionResult> AddProductType([FromBody] ProductTypeSaveResource saveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /* Pre-existence Test */
            var filter = new MdaProductTypeQuery()
            {
                Name = saveResource.Name
            };
            var productTypeFromRepo = await _repo.GetProductTypes(filter);

            if (productTypeFromRepo.Any())
            {
                return(BadRequest($"Product Type {saveResource.Name} already exists."));
            }

            var productType = _mapper.Map <MdaProductType>(saveResource);

            productType.CreatedBy = User.Identity.Name;

            _repo.Add(productType);

            if (await _repo.SaveAll())
            {
                return(Ok(productType));
            }

            return(BadRequest("Failed to add product type."));
        }
        public async Task <IActionResult> AddDepartment([FromBody] DepartmentSaveResource departmentSaveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /* Test for prexistence */
            var departmentFromRepo = await _repo.GetDepartments(new MdaDepartmentQuery()
            {
                Name = departmentSaveResource.Name, Active = Convert.ToByte(departmentSaveResource.Active == true ? 1 : 0)
            });

            if (departmentFromRepo.Any())
            {
                return(BadRequest($"Department {departmentSaveResource.Name} already exists"));
            }

            var department = _mapper.Map <MdaDepartment>(departmentSaveResource);

            department.CreatedBy = User.Identity.Name;

            _repo.Add(department);

            if (await _repo.SaveAll())
            {
                return(Ok(department));
            }

            return(BadRequest("Failed to add department"));
        }
Esempio n. 10
0
        public async Task <IActionResult> AddDeviceDateType([FromBody] DeviceDateTypeSaveResource deviceDateTypeSaveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /* Test for prexistence */
            var deviceDateTypeFromRepo = await _repo.GetDeviceDateTypes(new MdaDeviceDateTypeQuery()
            {
                Name = deviceDateTypeSaveResource.Name
            }, true);

            if (deviceDateTypeFromRepo.Any())
            {
                return(BadRequest($"DateType {deviceDateTypeSaveResource.Name} already exists"));
            }

            var deviceDateType = _mapper.Map <MdaDeviceDateType>(deviceDateTypeSaveResource);

            deviceDateType.CreatedBy = User.Identity.Name;

            _repo.Add(deviceDateType);

            if (await _repo.SaveAll())
            {
                return(Ok(deviceDateType));
            }

            return(BadRequest("Failed to add device date"));
        }