Пример #1
0
        public async Task <IHttpActionResult> PostCourse(ViewModels.Course dto)
        {
            // return Ok(client);
            if (dto == null)
            {
                return(Exceptions.getNullException(ModelState));
            }
            if (!ModelState.IsValid)
            {
                // return BadRequest(ModelState);
                return(Exceptions.getModelValidationException(ModelState));
            }
            var validate = unitOfWork.CourseRepository.Validate(dto);

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

            Course entity = null;

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

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

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

            //ViewModels.Location.Fill(entity, dto);
            ViewModels.Course.Fill(entity, dto);
            unitOfWork.CourseRepository.FillCourseRelatedAircraftTypes(entity, dto);
            unitOfWork.CourseRepository.FillCourseRelatedCourses(entity, dto);
            unitOfWork.CourseRepository.FillCourseRelatedCourseTypes(entity, dto);
            unitOfWork.CourseRepository.FillCourseRelatedEmployees(entity, dto);
            unitOfWork.CourseRepository.FillCourseRelatedJobGroups(entity, dto);
            unitOfWork.CourseRepository.FillCourseRelatedStudyFields(entity, dto);
            unitOfWork.CourseRepository.FillAircraftTypes(entity, dto);
            unitOfWork.CourseRepository.FillCourseCatRates(entity, dto);

            //if (dto.Id != -1 && entity.FullCode != oldFullCode)
            //    unitOfWork.LocationRepository.UpdateChildren(entity, entity.FullCode);
            var saveResult = await unitOfWork.SaveAsync();

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

            dto.Id = entity.Id;
            return(Ok(dto));
        }
Пример #2
0
        public virtual CustomActionResult Validate(ViewModels.Course dto)
        {
            var c = dbSet.FirstOrDefault(q => q.Id != dto.Id && q.DateStart == dto.DateStart && q.CourseTypeId == dto.CourseTypeId && q.OrganizationId == dto.OrganizationId);

            if (c != null)
            {
                return(Exceptions.getDuplicateException("Course-01", "Type-Organization-DateStart"));
            }
            //var checkByTitle = GetByTitleInParent(dto.Id, dto.ParentId, dto.Title);
            //if (checkByTitle != null)
            //    return Exceptions.getDuplicateException("Location-01", "Title");
            //var checkByCode = GetByFullCode(dto.Id, dto.CustomerId, dto.FullCode);
            //if (checkByCode != null)
            //    return Exceptions.getDuplicateException("Location-02", "FullCode");

            return(new CustomActionResult(HttpStatusCode.OK, ""));
        }
Пример #3
0
 public static void FillDto(Models.Course entity, ViewModels.Course course)
 {
     course.Id                        = entity.Id;
     course.CourseTypeId              = entity.CourseTypeId;
     course.DateStart                 = entity.DateStart;
     course.DateStartP                = entity.DateStartP;
     course.DateEnd                   = entity.DateEnd;
     course.DateEndP                  = entity.DateEndP;
     course.Instructor                = entity.Instructor;
     course.Location                  = entity.Location;
     course.Department                = entity.Department;
     course.OrganizationId            = entity.OrganizationId;
     course.Duration                  = entity.Duration;
     course.DurationUnitId            = entity.DurationUnitId;
     course.StatusId                  = entity.StatusId;
     course.Remark                    = entity.Remark;
     course.Capacity                  = entity.Capacity;
     course.Tuition                   = entity.Tuition;
     course.CurrencyId                = entity.CurrencyId;
     course.DateDeadlineRegistration  = entity.DateDeadlineRegistration;
     course.DateDeadlineRegistrationP = entity.DateDeadlineRegistrationP;
     course.TrainingDirector          = entity.TrainingDirector;
     course.Title                     = entity.Title;
     course.AircraftTypeId            = entity.AircraftTypeId;
     course.AircraftModelId           = entity.AircraftModelId;
     course.CaoTypeId                 = entity.CaoTypeId;
     course.Recurrent                 = entity.Recurrent;
     course.Interval                  = entity.Interval;
     course.CalanderTypeId            = entity.CalanderTypeId;
     course.IsInside                  = entity.IsInside;
     course.Quarantine                = entity.Quarantine;
     course.DateStartPractical        = entity.DateStartPractical;
     course.DateEndPractical          = entity.DateEndPractical;
     course.DateStartPracticalP       = entity.DateStartPracticalP;
     course.DateEndPracticalP         = entity.DateEndPracticalP;
     course.DurationPractical         = entity.DurationPractical;
     course.DurationPracticalUnitId   = entity.DurationPracticalUnitId;
     course.IsGeneral                 = entity.IsGeneral;
     course.CustomerId                = entity.CustomerId;
     course.No                        = entity.No;
     course.IsNotificationEnabled     = entity.IsNotificationEnabled;
 }
Пример #4
0
 public static void Fill(Models.Course entity, ViewModels.Course course)
 {
     entity.Id                        = course.Id;
     entity.CourseTypeId              = course.CourseTypeId;
     entity.DateStart                 = course.DateStart;
     entity.DateStartP                = Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateDigital(course.DateStart));
     entity.DateEnd                   = course.DateEnd;
     entity.DateEndP                  = course.DateEnd != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateDigital((DateTime)course.DateEnd)) : null;
     entity.Instructor                = course.Instructor;
     entity.Location                  = course.Location;
     entity.Department                = course.Department;
     entity.OrganizationId            = course.OrganizationId;
     entity.Duration                  = course.Duration;
     entity.DurationUnitId            = course.DurationUnitId;
     entity.StatusId                  = course.StatusId;
     entity.Remark                    = course.Remark;
     entity.Capacity                  = course.Capacity;
     entity.Tuition                   = course.Tuition;
     entity.CurrencyId                = course.CurrencyId;
     entity.DateDeadlineRegistration  = course.DateDeadlineRegistration;
     entity.DateDeadlineRegistrationP = course.DateDeadlineRegistration != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateDigital((DateTime)course.DateDeadlineRegistration)) : null;
     entity.TrainingDirector          = course.TrainingDirector;
     entity.Title                     = course.Title;
     entity.AircraftTypeId            = course.AircraftTypeId;
     entity.AircraftModelId           = course.AircraftModelId;
     entity.CaoTypeId                 = course.CaoTypeId;
     entity.Recurrent                 = course.Recurrent;
     entity.Interval                  = course.Interval;
     entity.CalanderTypeId            = course.CalanderTypeId;
     entity.IsInside                  = course.IsInside;
     entity.Quarantine                = course.Quarantine;
     entity.DateStartPractical        = course.DateStartPractical;
     entity.DateEndPractical          = course.DateEndPractical;
     entity.DateStartPracticalP       = course.DateStartPractical != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateDigital((DateTime)course.DateStartPractical)) : null;;
     entity.DateEndPracticalP         = course.DateEndPractical != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateDigital((DateTime)course.DateEndPractical)) : null;;
     entity.DurationPractical         = course.DurationPractical;
     entity.DurationPracticalUnitId   = course.DurationPracticalUnitId;
     entity.IsGeneral                 = course.IsGeneral;
     entity.CustomerId                = course.CustomerId;
     entity.No                        = course.No;
     entity.IsNotificationEnabled     = course.IsNotificationEnabled;
 }
Пример #5
0
        public void FillCourseCatRates(Course course, ViewModels.Course dto)
        {
            var existing = this.context.CourseCatRates.Where(q => q.CourseId == course.Id).ToList();
            var deleted  = (from x in existing
                            where dto.CourseCatRates.IndexOf(x.CourseId) == -1
                            select x).ToList();
            var added = (from x in dto.CourseCatRates
                         where existing.FirstOrDefault(q => q.CourseId == x) == null
                         select x).ToList();

            foreach (var x in deleted)
            {
                context.CourseCatRates.Remove(x);
            }
            foreach (var x in added)
            {
                context.CourseCatRates.Add(new CourseCatRate()
                {
                    Course    = course,
                    CatRateId = x
                });
            }
        }
Пример #6
0
        public void FillCourseRelatedStudyFields(Course course, ViewModels.Course dto)
        {
            var existing = this.context.CourseRelatedStudyFields.Where(q => q.CourseId == course.Id).ToList();
            var deleted  = (from x in existing
                            where dto.CourseRelatedStudyFields.FirstOrDefault(q => q.Id == x.StudyFieldId) == null
                            select x).ToList();
            var added = (from x in dto.CourseRelatedStudyFields
                         where existing.FirstOrDefault(q => q.StudyFieldId == x.Id) == null
                         select x).ToList();

            foreach (var x in deleted)
            {
                context.CourseRelatedStudyFields.Remove(x);
            }
            foreach (var x in added)
            {
                context.CourseRelatedStudyFields.Add(new CourseRelatedStudyField()
                {
                    Course       = course,
                    StudyFieldId = x.Id,
                });
            }
        }
Пример #7
0
        public async Task <ViewModels.Course> GetCourseDto(int id)
        {
            var course   = new ViewModels.Course();
            var dbcourse = await context.Courses.FirstOrDefaultAsync(q => q.Id == id);

            ViewModels.Course.FillDto(dbcourse, course);
            course.CourseAircraftTypes = await context.CourseAircraftTypes.Where(q => q.CourseId == id).Select(q => q.AircraftTypeId).ToListAsync();

            course.CourseCatRates = await context.CourseCatRates.Where(q => q.CourseId == id).Select(q => q.CatRateId).ToListAsync();

            course.CourseRelatedAircraftTypes = (await(from x in context.CourseRelatedAircraftTypes
                                                       join y in context.ViewAircraftTypes on x.AircraftTypeId equals y.Id
                                                       where x.CourseId == id
                                                       select y).ToListAsync()).Select(q => new ViewModels.AircraftType()
            {
                Id             = q.Id,
                Manufacturer   = q.Manufacturer,
                ManufacturerId = q.ManufacturerId,
                Remark         = q.Remark,
                Type           = q.Type
            }).ToList();
            course.CourseRelatedCourses = (await(from x in context.CourseRelatedCourses
                                                 join y in context.ViewCourses on x.RelatedCourseId equals y.Id
                                                 where x.CourseId == id
                                                 select y).ToListAsync()).Select(q => new ViewModels.CourseView()
            {
                Id           = q.Id,
                No           = q.No,
                Title        = q.Title,
                DateStart    = q.DateStart,
                DateEnd      = q.DateEnd,
                Organization = q.Organization,
                Instructor   = q.Instructor,
            }).ToList();
            course.CourseRelatedCourseTypes = (await(from x in context.CourseRelatedCourseTypes
                                                     join y in context.ViewCourseTypes on x.CourseTypeId equals y.Id
                                                     where x.CourseId == id
                                                     select y).ToListAsync()).Select(q => new ViewModels.CourseType()
            {
                Title  = q.Title,
                Remark = q.Remark,
                Id     = q.Id,
            }).ToList();
            course.CourseRelatedEmployees = (await(from x in context.CourseRelatedEmployees
                                                   join y in context.ViewEmployees on x.EmployeeId equals y.Id
                                                   where x.CourseId == id
                                                   select y).ToListAsync()).Select(q => new ViewModels.EmployeeView()
            {
                Name            = q.Name,
                NID             = q.NID,
                PID             = q.PID,
                Location        = q.Location,
                CaoCardNumber   = q.CaoCardNumber,
                NDTNumber       = q.NDTNumber,
                DateJoinCompany = q.DateJoinCompany,
                Id   = q.Id,
                IDNo = q.IDNo,
            }).ToList();
            course.CourseRelatedGroups = (await(from x in context.CourseRelatedGroups
                                                join y in context.ViewJobGroups on x.GroupId equals y.Id
                                                where x.CourseId == id
                                                select y).ToListAsync()).Select(q => new ViewModels.JobGroup()
            {
                Title    = q.Title,
                FullCode = q.FullCode,
                Remark   = q.Remark,
                Parent   = q.Parent,
                Id       = q.Id,
            }).ToList();
            course.CourseRelatedStudyFields = (await(from x in context.CourseRelatedStudyFields
                                                     join y in context.ViewOptions on x.StudyFieldId equals y.Id
                                                     where x.CourseId == id
                                                     select y).ToListAsync()).Select(q => new ViewModels.Option()
            {
                Title = q.Title,

                Parent = q.Parent,
                Id     = q.Id,
            }).ToList();


            return(course);
        }