Пример #1
0
        public async Task <IHttpActionResult> DeleteCertificate(ViewModels.Certificate dto)
        {
            var entity = await unitOfWork.PersonCourseRepository.GetByID(dto.Id);

            if (entity == null)
            {
                return(NotFound());
            }



            var canDelete = unitOfWork.PersonCourseRepository.CanDelete(entity);

            if (canDelete.Code != HttpStatusCode.OK)
            {
                return(canDelete);
            }

            unitOfWork.PersonCourseRepository.Delete(entity);

            var saveResult = await unitOfWork.SaveAsync();

            if (saveResult.Code != HttpStatusCode.OK)
            {
                return(saveResult);
            }

            return(Ok(dto));
        }
Пример #2
0
        /// <summary>
        /// Convert a given Certificate to a ViewModel
        /// </summary>
        public static ViewModels.Certificate ToViewModel(this MicrosoftDynamicsCRMbcgovCertificate certificate)
        {
            ViewModels.Certificate result = null;
            if (certificate != null)
            {
                result = new ViewModels.Certificate()
                {
                    Id               = certificate.BcgovCertificateid,
                    Name             = certificate.BcgovName,
                    ExpiryDateString = certificate.BcgovExpirydatelongdatestring,
                    ExpiryDate       = certificate.BcgovExpirydate,
                    IssueDate        = certificate.BcgovIssueddate,
                    IssueDateString  = certificate.BcgovIssueddatelongdatestring,
                };

                // add the CertificateApprovedProducts
                if (certificate?.BcgovCertificateBcgovCertificateapprovedproductCertificateId?.Count > 0)
                {
                    result.ApprovedProducts = new List <CertificateApprovedProduct>();
                    foreach (var product in certificate.BcgovCertificateBcgovCertificateapprovedproductCertificateId)
                    {
                        result.ApprovedProducts.Add(product.ToViewModel());
                    }
                }
            }
            return(result);
        }
Пример #3
0
 public static void Fill(Models.PersonCourse entity, ViewModels.Certificate certificate)
 {
     entity.Id         = certificate.Id;
     entity.PersonId   = certificate.PersonId;
     entity.CourseId   = certificate.CourseId;
     entity.DateIssue  = certificate.DateIssue;
     entity.DateExpire = certificate.DateExpire;
     entity.CerNumber  = certificate.No;
     entity.StatusId   = 71;
 }
Пример #4
0
        public virtual CustomActionResult ValidateCertificate(ViewModels.Certificate dto)
        {
            var c = context.ViewCertificates.FirstOrDefault(q => q.Id != dto.Id && q.PersonId == dto.PersonId && DbFunctions.TruncateTime(q.DateIssue) == DbFunctions.TruncateTime(dto.DateIssue) && q.CourseTypeId == dto.CourseTypeId && q.CourseTitle.ToLower() == dto.CourseTitle.ToLower());

            if (c != null)
            {
                return(Exceptions.getDuplicateException("Certificate-01", "Certificate"));
            }


            return(new CustomActionResult(HttpStatusCode.OK, ""));
        }
Пример #5
0
        public async Task <IHttpActionResult> PostCertification(ViewModels.Certificate dto)
        {
            // return Ok(client);
            if (dto == null)
            {
                return(Exceptions.getNullException(ModelState));
            }
            if (!ModelState.IsValid)
            {
                // return BadRequest(ModelState);
                return(Exceptions.getModelValidationException(ModelState));
            }
            var validate = unitOfWork.PersonCourseRepository.ValidateCertificate(dto);

            if (validate.Code != HttpStatusCode.OK)
            {
                return(validate);
            }

            PersonCourse entity = null;

            if (dto.Id == -1)
            {
                entity = new PersonCourse();
                unitOfWork.PersonCourseRepository.Insert(entity);
            }

            else
            {
                entity = await unitOfWork.PersonCourseRepository.GetByID(dto.Id);
            }

            if (entity == null)
            {
                return(Exceptions.getNotFoundException());
            }

            //ViewModels.Location.Fill(entity, dto);
            ViewModels.Certificate.Fill(entity, dto);



            var saveResult = await unitOfWork.SaveAsync();

            if (saveResult.Code != HttpStatusCode.OK)
            {
                return(saveResult);
            }

            dto.Id = entity.Id;
            return(Ok(dto));
        }
Пример #6
0
 /// <summary>
 /// Convert a given Certificate to a ViewModel
 /// </summary>
 public static ViewModels.Certificate ToViewModel(this MicrosoftDynamicsCRMbcgovCertificate certificate)
 {
     ViewModels.Certificate result = null;
     if (certificate != null)
     {
         result = new ViewModels.Certificate()
         {
             Id                  = certificate.BcgovCertificateid,
             Name                = certificate.BcgovName,
             ExpiryDateString    = certificate.BcgovExpirydatelongdatestring,
             ExpiryDate          = certificate.BcgovExpirydate,
             IssueDate           = certificate.BcgovIssueddate,
             IssueDateString     = certificate.BcgovIssueddatelongdatestring,
             ApprovedIntendedUse = certificate.BcgovApprovedintendeduse
         };
     }
     return(result);
 }