private List <Guid> AddMobileDevices(List <MobileDevice> mobileDevices) { List <Guid> insertedMobileDevices = new List <Guid>(); insertedMobileDevices.AddRange(mobileDevices.Where(ben => ben.BeneficiaryId != Guid.Empty).Select(ben => ben.BeneficiaryId)); mobileDevices.RemoveAll(ben => ben.BeneficiaryId != Guid.Empty); // Verifies if Serial Number is already in DB if (_db.MobileDevices .Select(mob => mob.MobileDeviceSerialNumber) .Where(serial => mobileDevices.Select(mob => mob.MobileDeviceSerialNumber).Contains(serial)) .ToList().Count > 0) { return(null); } foreach (var mobile in mobileDevices) { mobile.IsDeleted = false; if (MobileDeviceValidations.MobileDeviceIsValid(mobile)) { insertedMobileDevices.Add(_db.MobileDevices.Add(mobile).Entity.BeneficiaryId); } } if (insertedMobileDevices.Count == mobileDevices.Count) { return(insertedMobileDevices); } return(null); }
public IActionResult PostMobileDevice([FromBody] MobileDevice mobileDevice) { mobileDevice.BeneficiaryId = Guid.NewGuid(); if (!MobileDeviceValidations.MobileDeviceIsValid(mobileDevice)) { return(Forbid()); } _mobileDeviceRepository.Add(mobileDevice); return(Ok(mobileDevice)); }
public IActionResult UpdateMobileDevice(Guid id, [FromBody] MobileDevice mobileDevice) { if (!MobileDeviceValidations.MobileDeviceIsValid(mobileDevice)) { return(Forbid()); } var obj = (MobileDevice)_beneficiaryRepository.Find(id); obj.IsDeleted = mobileDevice.IsDeleted; obj.MobileDeviceBrand = mobileDevice.MobileDeviceBrand; obj.MobileDeviceInvoiceValue = mobileDevice.MobileDeviceInvoiceValue; obj.MobileDeviceManufactoringYear = mobileDevice.MobileDeviceManufactoringYear; obj.MobileDeviceModel = mobileDevice.MobileDeviceModel; obj.MobileDeviceSerialNumber = mobileDevice.MobileDeviceSerialNumber; obj.MobileDeviceType = mobileDevice.MobileDeviceType; return(Ok(_beneficiaryRepository.Update(id, obj))); }