예제 #1
0
        public async Task Create(T entidad)
        {
            await _context.Set <T>().AddAsync(entidad);


            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Password,Salt,Gender,Phone,Address,DoB,CreatedAt,UpdatedAt,Status")] Student student, int[] ClassRoomId)
        {
            if (HttpContext.Session.GetString("currentLogin") == null)
            {
                return(Redirect("/Authentication/Login"));
            }
            if (ModelState.IsValid)
            {
                foreach (var id in ClassRoomId)
                {
                    var classroom       = _context.ClassRoom.Find(id);
                    StudentClassRoom sc = new StudentClassRoom
                    {
                        ClassRoom = classroom,
                        Student   = student
                    };
                    _context.Add(sc);
                }
                student.GenerateSalt();
                student.EncryptPassword();
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
예제 #3
0
        public async Task <IActionResult> PutClassInfo(int id, ClassInfo classInfo)
        {
            if (id != classInfo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(classInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClassInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Id,Type,Value,CreatedAt,UpdateAt,CourseId,StudentId,Status")] Mark mark)
        {
            if (HttpContext.Session.GetString("currentLogin") == null)
            {
                return(Redirect("/Authentication/Login"));
            }
            var checkMark = _context.Mark.Where(a => a.StudentId == mark.StudentId).Where(m => m.Type == mark.Type)
                            .Where(d => d.CourseId == mark.CourseId).FirstOrDefault();

            if (checkMark != null)
            {
                TempData["Fail"] = "Học sinh đã có điểm này";
                return(RedirectToAction(nameof(Create)));
            }

            if (ModelState.IsValid)
            {
                if (mark.Value > 5)
                {
                    mark.Status = MarkStatus.PASS;
                }
                else
                {
                    mark.Status = MarkStatus.FAIL;
                }
                _context.Add(mark);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]  = new SelectList(_context.Course, "Id", "Name", mark.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "Name", mark.StudentId);
            return(View(mark));
        }
        public async Task <IActionResult> PutClassRoom([FromRoute] int id, [FromBody] ClassRoom classRoom)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != classRoom.Id)
            {
                return(BadRequest());
            }

            _context.Entry(classRoom).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClassRoomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description,CreatedAt,ExpiredAt,Status")] Course course, int[] courseId)
        {
            if (HttpContext.Session.GetString("currentLogin") == null)
            {
                return(Redirect("/Authentication/Login"));
            }
            if (ModelState.IsValid)
            {
                foreach (var id in courseId)
                {
                    var             courseClass    = _context.ClassRoom.Find(id);
                    ClassRoomCourse CourseCategory = new ClassRoomCourse()
                    {
                        ClassRoom = courseClass,
                        Course    = course
                    };
                    _context.Add(CourseCategory);
                }
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
예제 #7
0
        public async Task <ActionResult <Add_StudentInfo> > PostAdd_StudentInfo(Add_StudentInfo add_StudentInfo)
        {
            _context.Add_StudentInfo.Add(add_StudentInfo);

            _context.SaveChangesAsync();


            return(add_StudentInfo);
        }
예제 #8
0
        public async Task <int> Delete(Guid Id)
        {
            var entity = await db.Jobs.FirstOrDefaultAsync(x => x.Id == Id.ToString());

            db.Jobs.Remove(entity);
            var rs = await db.SaveChangesAsync();

            return(rs);
        }
        public async Task <bool> Delete(string functionId)
        {
            var listFR = await db.Function_Roles.Where(x => x.FunctionId == functionId).ToListAsync();

            db.Function_Roles.RemoveRange(listFR);
            var eFunction = await db.Functions.FirstOrDefaultAsync(x => x.FunctionId == functionId);

            db.Functions.Remove(eFunction);
            return(await db.SaveChangesAsync() > 0);
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("Id,Name,LogoPath")] TeamEntity teamEntity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teamEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teamEntity));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Password,CreatedAt,UpdatedAt,Status")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(Redirect("/Authentication/Login"));
            }
            return(View(teacher));
        }
예제 #12
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,CreatedAt,UpdatedAt,Status")] ClassRoom classRoom)
        {
            if (HttpContext.Session.GetString("currentLogin") == null)
            {
                return(Redirect("/Authentication/Login"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(classRoom);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(classRoom));
        }
예제 #13
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = await _datacontext.Activities.FindAsync(request.Id);

                if (activity == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Activity = "Could not Find Activity" });
                }
                var user = await _datacontext.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var attendance = await _datacontext.UserActivities
                                 .SingleOrDefaultAsync(x => x.ActivityId == activity.activityId && x.AppUserId == user.Id);


                if (attendance == null)
                {
                    return(Unit.Value);
                }
                if (attendance.IsHost)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Attenddance = "Düzenliyici iken kendini çıkartamazsın" });
                }
                _datacontext.UserActivities.Remove(attendance);

                var success = await _datacontext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
예제 #14
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Posts.Add(request.Post);
                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
예제 #15
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await _datacontext.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var photo = user.Photos.FirstOrDefault(x => x.Id == request.Id);

                if (photo == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Photo = "Not Found" });
                }
                if (photo.IsMain)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Photo = "You Cannot delete Your main Photo" });
                }
                var result = _photoAccessor.DeletePhoto(photo.Id);

                if (result == null)
                {
                    throw new Exception("Problem Deleteing Photo");
                }

                user.Photos.Remove(photo);
                // Handler Logic
                var success = await _datacontext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
예제 #16
0
            public async Task <CommentDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = await _datacontext.Activities.FindAsync(request.ActivityId);

                if (activity == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Activity = "Not Found" });
                }
                // Yada Kayıtlı olan tokendaki ismi buraya geçeriz
                var user = await _datacontext.Users.SingleOrDefaultAsync(x => x.UserName == request.Username);

                var comment = new Comment
                {
                    Author     = user,
                    Activity   = activity,
                    MyProperty = request.Body,
                    CreatedAt  = DateTime.Now
                };

                activity.Comments.Add(comment);
                // Handler Logic
                var success = await _datacontext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(_mapper.Map <CommentDto>(comment));
                }

                throw new Exception("Problem saving changes");
            }
예제 #17
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = new Activity
                {
                    activityId  = request.ActivityId,
                    Title       = request.Title,
                    Description = request.Description,
                    Category    = request.Category,
                    Date        = request.Date,
                    City        = request.City,
                    Venue       = request.Venue
                };

                _datacontext.Activities.Add(activity);


                var user = await _datacontext.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var attende = new UserActivity
                {
                    AppUser    = user,
                    Activity   = activity,
                    IsHost     = true,
                    DateJoined = DateTime.Now
                };

                _datacontext.UserActivities.Add(attende);
                var success = await _datacontext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
예제 #18
0
            public async Task <Photo> Handle(Command request, CancellationToken cancellationToken)
            {
                var photoUploadResult = _photoAccessor.AddPhoto(request.File);

                var user = await _datacontext.Users
                           .SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var photo = new Photo
                {
                    Url = photoUploadResult.Url,
                    Id  = photoUploadResult.PublicId
                };



                if (!user.Photos.Any(x => x.IsMain))
                {
                    photo.IsMain = true;
                }

                user.Photos.Add(photo);
                // Handler Logic
                var success = await _datacontext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(photo);
                }
                throw new Exception("Problem saving changes");
            }
예제 #19
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = await _datacontext.Activities.FindAsync(request.Id);

                if (activity == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Activity = "Could not Find Activity" });
                }
                var user = await _datacontext.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var attendance = await _datacontext.UserActivities
                                 .SingleOrDefaultAsync(x => x.ActivityId == activity.activityId && x.AppUserId == user.Id);

                // .SingleOrDefaultAsync(x => x.ActivityId == activity.ActivityId && x.AppUserId == user.Id);
                // Handler Logic EAGER LOADİNG !!!!
                if (attendance != null)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Attendance = "Bu Aktiviye Zaten Katılıyorsun" });
                }
                attendance = new UserActivity
                {
                    Activity   = activity,
                    AppUser    = user,
                    IsHost     = false,
                    DateJoined = DateTime.Now
                };
                _datacontext.UserActivities.Add(attendance);
                var success = await _datacontext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
예제 #20
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                await _context.CategoryList.AddAsync(request.list);

                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
예제 #21
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var post = await _context.Posts.FindAsync(request.id);

                _context.Remove(post);
                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
        public async Task <int> Delete(string Id)
        {
            try
            {
                //var listFR = await db.Function_Roles.Where(x => x.RoleId == Id).ToListAsync();
                //db.Function_Roles.RemoveRange(listFR);
                var entity = await db.Roles.FindAsync(Id);

                db.Roles.Remove(entity);
                var rs = await db.SaveChangesAsync();

                return(rs);
            }
            catch (DbUpdateException)
            {
                return(-1); // khong xoa duoc khoa ngoai
            }
        }
예제 #23
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var category = await _context.CategoryList.FindAsync(request.id);

                _context.CategoryList.Remove(category);
                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
        public async Task <int> Insert(KhachHangLogViewModels model)
        {
            model.Id = Guid.NewGuid().ToString();
            var entity = mp.Map <KhachHangLog>(model);
            await db.KhachHangLogs.AddAsync(entity);

            var rs = await db.SaveChangesAsync();

            // thanh cong 1, o loi
            return(rs);
        }
예제 #25
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var category = await _context.CategoryList.FindAsync(request.list.Id);

                if (category != null)
                {
                    category.Cname = request.list.Cname ?? category.Cname;
                    await _context.SaveChangesAsync();
                }
                return(Unit.Value);
            }
        public async Task <bool> Delete(string id)
        {
            var entity = await _db.Notifications.FirstOrDefaultAsync(x => x.NotificationId == id);

            _db.Notifications.Remove(entity);
            return(await _db.SaveChangesAsync() > 0);
        }
예제 #27
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var observer = await _datacontext.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());


                var target = await _datacontext.Users.SingleOrDefaultAsync(x => x.UserName == request.Username);

                if (target == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { User = "******" });
                }

                //EagerLoading  var following = await datacontext. include theninclde diye

                // EAGER LOADİNG COMPLETE
                // var following = await _datacontext.Users
                //                                     .Include(x => x.Followers)
                //                                     .ThenInclude(x => x.ObserverId == observer.Id && x.TargetId == target.Id)
                //                                  .SingleOrDefaultAsync(x => x.UserName == request.Username);

                var following = await _datacontext.Followings.SingleOrDefaultAsync(x => x.ObserverId == observer.Id && x.TargetId == target.Id);



                if (following != null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { User = "******" });
                }

                if (following == null)
                {
                    following = new UserFollowing
                    {
                        Observer = observer,
                        Target   = target
                    };

                    _datacontext.Followings.Add(following);
                }
                // Handler Logic
                var success = await _datacontext.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
예제 #28
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                user.DisplayName = request.DisplayName ?? user.DisplayName;
                user.Bio         = request.Bio;

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
예제 #29
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var post = await _context.Posts.FindAsync(request.Post.Id);

                if (post != null)
                {
                    post.DisplayName = request.Post.DisplayName ?? post.DisplayName;
                    post.Description = request.Post.Description ?? post.Description;
                    post.Image       = request.Post.Image ?? post.Image;
                    post.Sizes       = request.Post.Sizes ?? post.Sizes;
                    post.price       = request.Post.price;
                    post.category    = request.Post.category ?? post.category;
                    await _context.SaveChangesAsync();
                }
                return(Unit.Value);
            }
        public async Task <ThongBaoViewModel> CreateAsync(ThongBaoViewModel viewModel)
        {
            ThongBao model = _mp.Map <ThongBao>(viewModel);
            await _db.ThongBaos.AddAsync(model);

            await _db.SaveChangesAsync();

            ThongBaoViewModel result = _mp.Map <ThongBaoViewModel>(model);

            return(result);
        }