public ResponseMessage UpdateComponentType(ComponentTypeDetails componentType, int id)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage = _componentTypeRepository.UpdateComponentType(componentType, id);
            return(responseMessage);
        }
        public ComponentTypeDetails GetComponentTypeById(int id)
        {
            ComponentTypeDetails componentType = _componentTypeRepository.getComponentTypeById(id);

            if (componentType == null)
            {
                return(null);
            }

            return(componentType);
        }
        public ComponentTypeDetails getComponentTypeById(int id)
        {
            ComponentTypeDetails response = new ComponentTypeDetails();
            var responsedb = _context.ComponentType.Where(x => x.Id == id && x.IsDelete == false).FirstOrDefault();

            if (responsedb != null)
            {
                response = _mapper.Map <ComponentTypeDetails> (responsedb);
            }

            return(response);
        }
        public ResponseMessage AddComponentType(ComponentTypeDetails componentType)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage = _componentTypeRepository.AddComponentType(componentType);

            if (responseMessage != null) //TODO
            {
                return(responseMessage);
            }
            else
            {
                return(new ResponseMessage()
                {
                    Message = "",
                });
            }
        }
Exemplo n.º 5
0
 public IActionResult UpdateComponentType(ComponentTypeDetails componentType, int id)
 {
     try {
         var response = _componentTypeService.UpdateComponentType(componentType, id);
         return(Ok(new { message = response.Message, code = 204 }));
     } catch (ValueNotFoundException e) {
         Util.LogError(e);
         return(StatusCode(StatusCodes.Status422UnprocessableEntity, new ErrorClass()
         {
             code = StatusCodes.Status422UnprocessableEntity.ToString(), message = e.Message
         }));
     } catch (Exception e) {
         Util.LogError(e);
         return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass()
         {
             code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong"
         }));
     }
 }
        public ResponseMessage UpdateComponentType(ComponentTypeDetails componentTypeDetails, int id)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            try {
                var componentType = _context.ComponentType.Where(x => x.Id == id && x.IsDelete == false).FirstOrDefault();
                if (componentType != null)
                {
                    if (_context.ComponentType.Where(x => x.Name == componentTypeDetails.Name && x.Id != id && x.IsDelete == false).Count() > 0)
                    {
                        throw new ValueNotFoundException("ComponentType Name already exist.");
                    }
                    else
                    {
                        componentType.Name        = componentTypeDetails.Name;
                        componentType.Description = componentTypeDetails.Description;
                        componentType.IsActive    = componentTypeDetails.isActive;
                        _context.SaveChanges();

                        /*AuditLogs audit = new AuditLogs () {
                         *  Action = "ComponentType",
                         *  Message = string.Format ("Update componentType  successfully {0}", componentTypeDetails.Name),
                         *  CreatedAt = DateTime.Now
                         * };
                         * _commonRepo.AuditLog (audit);*/

                        return(responseMessage = new ResponseMessage()
                        {
                            Message = "ComponentType updated successfully.",
                        });
                    }
                }
                else
                {
                    throw new ValueNotFoundException("ComponentType not available.");
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
        public ResponseMessage AddComponentType(ComponentTypeDetails componentTypeDetails)
        {
            ResponseMessage response = new ResponseMessage();

            try {
                //TODO: ID auto incremented??
                if (_context.ComponentType.Where(x => x.Id == componentTypeDetails.Id && x.IsDelete == false).Count() > 0)
                {
                    throw new ValueNotFoundException("ComponentType Id already exist.");
                }
                else if (_context.ComponentType.Where(x => x.Name == componentTypeDetails.Name && x.IsDelete == false).Count() > 0)
                {
                    throw new ValueNotFoundException("ComponentType Name already exist.");
                }
                else
                {
                    var componentType = _mapper.Map <ComponentType> (componentTypeDetails);
                    _context.ComponentType.Add(componentType);
                    _context.SaveChanges();

                    //TODO: is audit required for componentType?

                    /* AuditLogs audit = new AuditLogs () {
                     *   Action = "ComponentType",
                     *   Message = string.Format ("New ComponentType added successfully {0}", componentTypeDetails.Name),
                     *   CreatedAt = DateTime.Now
                     * };
                     * _commonRepo.AuditLog(audit);
                     */

                    return(response = new ResponseMessage()
                    {
                        Message = "ComponentType added successfully."
                    });
                }
            } catch (Exception ex) {
                throw ex;
            }
        }