public int Add(AddEquipmentDto model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new AddEquipmentException(model.Id, "Can not be an empty string");
            }
            if (string.IsNullOrEmpty(model.Type))
            {
                throw new AddEquipmentException(model.Id, "Can not be an empty string");
            }
            if (string.IsNullOrEmpty(model.Description))
            {
                throw new AddEquipmentException(model.Id, "Can not be an empty string");
            }
            if (model.Price < 0)
            {
                throw new AddEquipmentException(model.Id, "Price can not be less then 0!");
            }
            if (model.Name.Count() < 3 || model.Name.Count() > 30)
            {
                throw new AddEquipmentException(model.Id, "Name can not be less then 3 and bigger then 30!");
            }
            if (model.Type.Count() < 3)
            {
                throw new AddEquipmentException(model.Id, "Name can not be less then 3!");
            }
            if (model.Description.Count() < 10)
            {
                throw new AddEquipmentException(model.Id, "Description can not be less then 10!");
            }
            var equipment = _mapper.Map <AdditionalEquipment>(model);

            return(_addEquipmentRepo.Insert(equipment));
        }
        public int Update(AddEquipmentDto model)
        {
            if (model == null)
            {
                throw new AddEquipmentException(model.Id, "No such equipment to be updated!");
            }

            var mappedEquipment = _mapper.Map <AdditionalEquipment>(model);

            return(_addEquipmentRepo.Update(mappedEquipment));
        }
 public ActionResult <AdditionalEquipment> AddEquipment([FromBody] AddEquipmentDto equipment)
 {
     try
     {
         _equipment.Add(equipment);
         return(Ok("New equipment is successfuly added"));
     }
     catch (AddEquipmentException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
        public ActionResult Put(int id, [FromBody] AddEquipmentDto equipment)
        {
            try
            {
                _equipment.Update(equipment);

                return(Ok("Equipment changes is successfully!"));
            }
            catch (AddEquipmentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }