public async Task <bool> CreateCartItem(CartCreateRAO rao)
        {
            var entity = _mapper.Map <CartEntity>(rao);

            // Don't let people buy less than 1 of a product
            if (entity.Quantity < 1)
            {
                return(false);
            }

            // Don't let people buy products that don't exist
            if (!_context.ProductTableAccess.Any(x => x.ProductEntityId == entity.ProductEntityId))
            {
                return(false);
            }

            // If the user already has some of this product in their cart, combine the new and old orders together
            if (_context.CartTableAccess.Any(x => x.OwnerId == entity.OwnerId && x.ProductEntityId == entity.ProductEntityId))
            {
                _context.CartTableAccess.Single(x => x.OwnerId == entity.OwnerId && x.ProductEntityId == entity.ProductEntityId).Quantity += entity.Quantity;
            }

            else
            {
                await _context.CartTableAccess.AddAsync(entity);
            }

            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> CreateProduct(ProductCreateRAO rao)
        {
            var entity = _mapper.Map <ProductEntity>(rao);
            await _context.ProductTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);
        }
예제 #3
0
        //CREATE PERSON
        public async Task <bool> CreatePerson(PersonCreateRAO rao)
        {
            var entity = _mapper.Map <PersonEntity>(rao);
            await _context.PersonTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);
        }
예제 #4
0
        public async Task <bool> CreateWishlist(WishlistCreateRAO rao)
        {
            var entity = _mapper.Map <WishlistEntity>(rao);
            await _context.WishlistTableAccess.AddAsync(entity); //transactional ID created here

            return(await _context.SaveChangesAsync() == 1);
        }
        public async Task <bool> CreatePainting(PaintingCreateRAO rao)
        {
            var entity = _mapper.Map <PaintingEntity>(rao);

            await _context.PaintingTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);
        }
        public async Task <bool> CreatePurchase(PurchaseCreateChargeRAO rao)
        {
            var entity = _mapper.Map <PurchaseEntity>(rao);

            await _context.PurchaseTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);
        }
예제 #7
0
        public async Task <bool> CreateFood(FoodCreateRAO rao)
        {
            var entity = _mapper.Map <FoodEntity>(rao);

            await _context.FoodTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);
        }
예제 #8
0
        public async Task<bool> CreateEvent(EventCreateRAO rao)
        {
            var entity = _mapper.Map<EventEntity>(rao);

            await _context.EventTableAccess.AddAsync(entity);

            return await _context.SaveChangesAsync() == 1;
        }
예제 #9
0
        public async Task <bool> CreateCustomer(CustomerCreateRAO rao)
        {
            var entity = _mapper.Map <CustomerEntity>(rao);

            await _context.CustomerTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);

            throw new NotImplementedException();
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("DepartmentId,DepartmentName")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("TermId,TermName,TermStartDate,TermEndDate,TermYear,TermSeason")] StudyTerm studyTerm)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studyTerm);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(studyTerm));
        }
예제 #12
0
        public async Task <IActionResult> Create([Bind("StudentId,StudentFirstName,StudentLastName,StudentEnrollment,StudentPhone")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
예제 #13
0
        public async Task <IActionResult> Create([Bind("InstructorId,InstructorFirstName,InstructorLastName,InstructorPhone,InstructorHireDepartment")] Instructor instructor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(instructor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(instructor));
        }
예제 #14
0
        public async Task <IActionResult> Create([Bind("CourseId,CourseName,DepartmentId")] Courses courses)
        {
            if (ModelState.IsValid)
            {
                _context.Add(courses);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentId"] = new SelectList(_context.Department, "DepartmentId", "DepartmentId", courses.DepartmentId);
            return(View(courses));
        }
        public async Task <bool> CreateInterests(InterestsCreateRAO rao)
        {
            var entity = _mapper.Map <InterestsEntity>(rao);

            if (!_context.InterestsTableAccess.Any(e => e.OwnerId == rao.OwnerId))
            {
                await _context.InterestsTableAccess.AddAsync(entity);

                return(await _context.SaveChangesAsync() == 1);
            }

            throw new Exception("A profile for this user already exists");
        }
예제 #16
0
        public async Task <IActionResult> Create([Bind("CourseId,InstructorId,TermId")] TeachingAssignment teachingAssignment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teachingAssignment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]     = new SelectList(_context.Courses, "CourseId", "CourseId", teachingAssignment.CourseId);
            ViewData["InstructorId"] = new SelectList(_context.Instructor, "InstructorId", "InstructorId", teachingAssignment.InstructorId);
            ViewData["TermId"]       = new SelectList(_context.StudyTerm, "TermId", "TermId", teachingAssignment.TermId);
            return(View(teachingAssignment));
        }
예제 #17
0
        public async Task <IActionResult> Create([Bind("StudentId,CourseId,TermId")] Registration registration)
        {
            if (ModelState.IsValid)
            {
                _context.Add(registration);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]  = new SelectList(_context.Courses, "CourseId", "CourseId", registration.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Student, "StudentId", "StudentId", registration.StudentId);
            ViewData["TermId"]    = new SelectList(_context.StudyTerm, "TermId", "TermId", registration.TermId);
            return(View(registration));
        }
예제 #18
0
        public async Task <bool> CreateApplication(ApplicationCreateRAO applicationCreate, Guid ApplicationGuid)
        {
            var applicationEntity = _mapper.Map <ApplicationEntity>(applicationCreate);

            applicationEntity.DateCreated         = DateTime.Now;
            applicationEntity.ApplicationEntityId = ApplicationGuid;

            var contactEntity = _mapper.Map <ContactEntity>(applicationCreate.Contact);

            contactEntity.ApplicationEntityId = ApplicationGuid;

            var demographicEntity = _mapper.Map <DemographicEntity>(applicationCreate.Demographic);

            demographicEntity.ApplicationEntityId = ApplicationGuid;

            var educationEntity = _mapper.Map <EducationEntity>(applicationCreate.Education);

            educationEntity.ApplicationEntityId = ApplicationGuid;

            var experienceEntity = _mapper.Map <ExperienceEntity>(applicationCreate.Experience);

            experienceEntity.ApplicationEntityId = ApplicationGuid;

            await _context.ApplicationTableAccess.AddAsync(applicationEntity);

            await _context.ContactTableAccess.AddAsync(contactEntity);

            await _context.DemographicTableAccess.AddAsync(demographicEntity);

            await _context.EducationTableAccess.AddAsync(educationEntity);

            await _context.ExperienceTableAccess.AddAsync(experienceEntity);

            return(await _context.SaveChangesAsync() == 6);
        }
        public async Task <bool> CreateNote(NoteCreateRAO rao)
        {
            var entity = _mapper.Map <NoteEntity>(rao);

            _context.NoteTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);
        }
        public async Task <bool> CreateJob(JobCreateRAO rao)
        {
            var entity = _mapper.Map <JobEntity>(rao);

            _context.JobTableAccess.AddAsync(entity);

            return(await _context.SaveChangesAsync() == 1);
        }
예제 #21
0
 public async Task <int> CommitAsync()
 {
     return(await _context.SaveChangesAsync());
 }