Пример #1
0
        public async Task <ActionResult <Note> > CreateNote([FromBody] Note note)
        {
            _context.Add(note);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetById", new { id = note.Id }, note));
        }
Пример #2
0
        public async Task <IActionResult> Create(FileCreateViewModel vm, string categoryLessonId, int uniCategoryId, int depCategoryId)
        {
            int userid         = Convert.ToInt32(HttpContext.Session.GetInt32("UserId"));
            var categoryid     = Convert.ToInt32(categoryLessonId);
            var ctrgCourseName = await _context.CategoryTable.FirstOrDefaultAsync(p => p.Id == categoryid);

            var ctrgUni = await _context.CategoryTable.FirstOrDefaultAsync(p => p.Id == uniCategoryId);

            var ctrgDep = await _context.CategoryTable.FirstOrDefaultAsync(p => p.Id == depCategoryId);

            var usr = await _context.UserTable.FirstOrDefaultAsync(p => p.Id == userid);

            if (vm.FilePath == null || vm.Title == null || categoryid == 0 || uniCategoryId == 0 || depCategoryId == 0 || usr == null)
            {
                return(Json(new { ok = false }));
            }
            else
            {
                File file = new File();
                file.CourseName  = ctrgCourseName.Name;
                file.Title       = vm.Title;
                file.Description = vm.Description;
                file.FilePath    = vm.FilePath;
                file.AddedUser   = usr;
                file.UploadDate  = DateTime.Now;
                file.Category    = ctrgCourseName;
                file.University  = ctrgUni.Name;
                file.Department  = ctrgDep.Name;
                _context.Add(file);
                await _context.SaveChangesAsync();

                return(Json(new { ok = true }));
            }
        }
Пример #3
0
        public async Task <IActionResult> Register(string Name, string Surname, string University, string Department, string City, string Email, string Password, string ConfirmPassword)
        {
            var User = await _context.UserTable.FirstOrDefaultAsync(p => p.Email == Email);

            if (User != null)
            {
                ModelState.AddModelError("", "Bu E-mail'e ait bir hesap vardır ! Lütfen Tekrar Deneyiniz.");
            }
            else
            {
                if (Password == ConfirmPassword && Email != null && Name != null &&
                    Surname != null && University != null && Department != null && City != null)
                {
                    User   user1          = new User();
                    string hashedPassword = Helper.PasswordHelper.HashPassword(Password);
                    user1.City       = City;
                    user1.Department = Department;
                    user1.Email      = Email;
                    user1.Hash       = hashedPassword;
                    user1.Name       = Name;
                    user1.Surname    = Surname;
                    user1.University = University;
                    _context.Add(user1);
                    await _context.SaveChangesAsync();

                    return(Json(new { ok = true, newurl = Url.Action("Login") }));
                }
                else
                {
                    return(Json(new { ok = false, message = "Şifre veya Kullanıcı Adı Yanlış" }));
                    //ModelState.AddModelError("", "Tekrar Girilen Şifre Hatalı ! Lütfen Tekrar Deneyiniz.");
                }
            }
            return(View());
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("ID,Title,Notes,CreatedOn,CategoryId,UserId,IsDeleted")] Note note)
        {
            if (ModelState.IsValid)
            {
                _context.Add(note);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "ID", "ID", note.CategoryId);
            ViewData["UserId"]     = new SelectList(_context.Users, "ID", "ID", note.UserId);
            return(View(note));
        }
Пример #6
0
        public async Task <IActionResult> Create(
            [Bind("Email,Name,CreatedOn")] User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(user));
        }