public bool Save(TypeDto typeDto)
        {
            Type type = new Type
            {
                Id          = typeDto.Id,
                Name        = typeDto.Name,
                Description = typeDto.Description
            };

            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    if (typeDto.Id == 0)
                    {
                        unitOfWork.TypeRepository.Insert(type);
                    }
                    else
                    {
                        unitOfWork.TypeRepository.Update(type);
                    }
                    unitOfWork.Save();
                }
                return(true);
            }
            catch
            {
                Console.WriteLine(type);
                return(false);
            }
        }
 public bool Delete(int id)
 {
     try
     {
         using (UnitOfWork unitOfWork = new UnitOfWork())
         {
             Type type = unitOfWork.TypeRepository.GetByID(id);
             unitOfWork.TypeRepository.Delete(type);
             unitOfWork.Save();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #3
0
        public DeleteTypeResponse Delete(int id)
        {
            var response = new DeleteTypeResponse();
            try
            {
                var type = new Data.Entities.Type { Id = id };
                DataContext.Types.Attach(type);
                DataContext.Entry(type).State = EntityState.Deleted;
                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "KPI type item has been deleted successfully";
            }
            catch (DbUpdateException dbUpdateException)
            {
                response.Message = dbUpdateException.Message;
            }

            return response;
        }
        public TypeDto GetById(int id)
        {
            TypeDto typeDto = new TypeDto();

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                Type type = unitOfWork.TypeRepository.GetByID(id);

                if (type != null)
                {
                    typeDto = new TypeDto
                    {
                        Id          = type.Id,
                        Name        = type.Name,
                        Description = type.Description
                    };
                }
            }

            return(typeDto);
        }
Exemple #5
0
        public DeleteTypeResponse Delete(int id)
        {
            var response = new DeleteTypeResponse();

            try
            {
                var type = new Data.Entities.Type {
                    Id = id
                };
                DataContext.Types.Attach(type);
                DataContext.Entry(type).State = EntityState.Deleted;
                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message   = "KPI type item has been deleted successfully";
            }
            catch (DbUpdateException dbUpdateException)
            {
                response.Message = dbUpdateException.Message;
            }

            return(response);
        }