Exemplo n.º 1
0
        public WorkPermitTypes Update(WorkPermitTypes workPermitTypes, int id)
        {
            var workPermit = (from x in _context.WorkPermitTypes
                              where x.ID == workPermitTypes.ID
                              select x).FirstOrDefault();

            if (_context.WorkPermitTypes.Any(x => x.PermitType == workPermitTypes.PermitType))
            {
                throw new AppException("permit type is already Exists");
            }
            if (string.IsNullOrEmpty(workPermitTypes.PermitType))
            {
                throw new ArgumentException("permit type should not be Empty");
            }
            if (workPermit.ID == id)
            {
                workPermit.PermitType = workPermitTypes.PermitType;
            }


            _context.WorkPermitTypes.Update(workPermit);
            _context.SaveChanges();

            return(workPermit);
        }
Exemplo n.º 2
0
        public WorkPermitTypes Create(WorkPermitTypes workPermitTypes)
        {
            if (string.IsNullOrEmpty(workPermitTypes.PermitType))
            {
                throw new ArgumentException("Permit type  should not be empty ");
            }
            if (_context.WorkPermitTypes.Any(x => x.PermitType == workPermitTypes.PermitType))
            {
                throw new AppException("Permit type is already Exists");
            }
            _context.WorkPermitTypes.Add(workPermitTypes);
            _context.SaveChanges();

            return(workPermitTypes);
        }