예제 #1
0
        public ActionResult <Models.Enclosure> AddDeviceToEnclosure(int projectId, int enclosureId, Enclosure_Device enclosureDevice)
        {
            try
            {
                var enclosure = _enclosure.GetEnclosureById(enclosureId);
                if (enclosure.ProjectId != projectId)
                {
                    return(NotFound("Enclosure with that ProjectID doesn't exist!"));
                }

                Task.Run(() => { _enclosure.RecalculateTotalPrice(enclosure); });

                return(Created("https://localhost:5001/Project", _enclosure.AddNewDevice(projectId, enclosureId, enclosureDevice)));
            }
            catch (EnclosureNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error", ex);
                return(BadRequest());
            }
        }
예제 #2
0
 public ActionResult <Models.Enclosure> GetEnclosureById(int id)
 {
     try
     {
         return(Ok(_enclosure.GetEnclosureById(id)));
     }
     catch (EnclosureNotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         _logger.LogError("Error", ex);
         return(BadRequest(ex.Message));
     }
 }