Example #1
0
        /// <summary>
        /// Map PresentationAdd_DTO to PresentationDB, passes to Add DB-method the PresentationDB
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <Result <Presentation> > AddPresentationAsync(PresentationAdd_DTO model)
        {
            var presentationDb = _mapper.Map <PresentationAdd_DTO, PresentationDB>(model);

            _uow.Presentations.Add(presentationDb);

            try
            {
                await _uow.SaveAsync();

                return(Result <Presentation> .Ok(_mapper.Map <Presentation>(presentationDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <Presentation>) Result <Presentation> .Fail("Cannot save model"));
            }
            catch (DbUpdateException e)
            {
                return((Result <Presentation>) Result <Presentation> .Fail($"Cannot save model. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <Presentation>) Result <Presentation> .Fail("Invalid model"));
            }
        }
Example #2
0
        /// <summary>
        /// Map FeedbackAdd_DTO to FeedbackDB, passes to Add DB-method the FeedbackDB
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <Result <Feedback> > AddFeedbackAsync(FeedbackAdd_DTO model)
        {
            var feedbackDb = _mapper.Map <FeedbackAdd_DTO, FeedbackDB>(model);

            _uow.Feedbacks.Add(feedbackDb);

            try
            {
                await _uow.SaveAsync();

                return(Result <Feedback> .Ok(_mapper.Map <Feedback>(feedbackDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <Feedback>) Result <Feedback> .Fail("Cannot save model"));
            }
            catch (DbUpdateException e)
            {
                return((Result <Feedback>) Result <Feedback> .Fail($"Cannot save model. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <Feedback>) Result <Feedback> .Fail("Invalid model"));
            }
        }
Example #3
0
        /// <summary>
        /// Map CourseAdd_DTO to CourseDB, passes to Add DB-method the CourseDB
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <Result <Course> > AddCourseAsync(CourseAdd_DTO model)
        {
            var courseDb = _mapper.Map <CourseAdd_DTO, CourseDB>(model);

            _uow.Courses.Add(courseDb);

            try
            {
                await _uow.SaveAsync();

                return(Result <Course> .Ok(_mapper.Map <Course>(courseDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <Course>) Result <Course> .Fail("Cannot save model"));
            }
            catch (DbUpdateException e)
            {
                return((Result <Course>) Result <Course> .Fail($"Cannot save model. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <Course>) Result <Course> .Fail("Invalid model"));
            }
        }
Example #4
0
        /// <summary>
        /// Map UserAdd_DTO to TeacherDB, passes to Add DB-method the TeacherDB
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <Result <Teacher> > AddTeacherAsync(TeacherAdd_DTO model)
        {
            var teacherDb = _mapper.Map <TeacherAdd_DTO, TeacherDB>(model);

            _uow.Teachers.Add(teacherDb);

            try
            {
                await _uow.SaveAsync();

                return(Result <Teacher> .Ok(_mapper.Map <Teacher>(teacherDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <Teacher>) Result <Teacher> .Fail("Cannot save model"));
            }
            catch (DbUpdateException e)
            {
                return((Result <Teacher>) Result <Teacher> .Fail($"Cannot save model. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <Teacher>) Result <Teacher> .Fail("Invalid model"));
            }
        }
Example #5
0
        /// <summary>
        /// Map UserAdd_DTO to StudentDB, passes to Add DB-method the StudentDB
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <Result <Student> > AddStudentAsync(UserAdd_DTO model)
        {
            var studentDb = _mapper.Map <UserAdd_DTO, StudentDB>(model);

            _uow.Students.Add(studentDb);

            try
            {
                await _uow.SaveAsync();

                return(Result <Student> .Ok(_mapper.Map <Student>(studentDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <Student>) Result <Student> .Fail("Cannot save model"));
            }
            catch (DbUpdateException e)
            {
                return((Result <Student>) Result <Student> .Fail($"Cannot save model. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <Student>) Result <Student> .Fail("Invalid model"));
            }
        }