public async Task <long> AddEquipmentAsync(User user, AddEquipmentFormModel equipmentForm) { try { Equipment parent = null; if (equipmentForm.ParentId != null) { parent = _context.Equipments.FirstOrDefault(c => c.ParentId == equipmentForm.ParentId); } var isDuplicateEquipment = _context.Equipments.Any(c => c.EquipmentName == equipmentForm.EquipmentName); if (!isDuplicateEquipment) { var org = new Equipment() { Description = equipmentForm.Description, EquipmentName = equipmentForm.EquipmentName, ParentId = equipmentForm.ParentId }; await _context.Equipments.AddAsync(org); await _context.SaveChangesAsync(); return(org.Id); } throw new ExperienceManagementGlobalException(EquipmentServiceErrors.AddDuplicateEquipmentError); } catch (Exception ex) { throw new ExperienceManagementGlobalException(EquipmentServiceErrors.AddEquipmentError, ex); } }
public async Task <IActionResult> AddEquipment([FromBody] AddEquipmentFormModel equipmentForm) { var equipments = await _equipmentService.AddEquipmentAsync(HttpContext.GetUser(), equipmentForm); return(Ok(GetRequestResult(equipments))); }