Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public async Task <bool> ChangeActiveCourseStatus(ViewModels.ActiveCourseStatus dto)
        {
            try
            {
                var query = await(from x in context.PersonCourses
                                  where x.CourseId == dto.CourseId && dto.People.Contains((int)x.PersonId)
                                  select x).ToListAsync();
                //pending
                if (dto.StatusId != 72)
                {
                    foreach (var x in dto.People)
                    {
                        var item = query.FirstOrDefault(q => q.PersonId == x);
                        if (item == null)
                        {
                            item = new PersonCourse()
                            {
                                PersonId = x,
                                CourseId = dto.CourseId,
                            };
                            context.PersonCourses.Add(item);
                        }
                        item.StatusId        = dto.StatusId;
                        item.DateStatus      = DateTime.Now;
                        item.StatusConfirmed = true;
                        item.Remark          = dto.Remark;
                        item.CerNumber       = null;
                        item.DateIssue       = null;
                        if (dto.StatusId == 71)
                        {
                            item.CerNumber = dto.No;
                            item.DateIssue = dto.IssueDate;
                        }
                    }
                }
                else
                {
                    foreach (var x in query)
                    {
                        context.PersonCourses.Remove(x);
                    }
                }


                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public static PersonCourse CreatePersonCourse(string partyNumber, string courses, global::System.DateTimeOffset startDate, global::System.DateTimeOffset endDate, global::Microsoft.Dynamics.DataEntities.Person person)
        {
            PersonCourse personCourse = new PersonCourse();

            personCourse.PartyNumber = partyNumber;
            personCourse.Courses     = courses;
            personCourse.StartDate   = startDate;
            personCourse.EndDate     = endDate;
            if ((person == null))
            {
                throw new global::System.ArgumentNullException("person");
            }
            personCourse.Person = person;
            return(personCourse);
        }