Example #1
0
        public virtual async Task <T> Create(T obj)
        {
            _context.Add(obj);
            await _context.SaveChangesAsync();

            return(obj);
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Information,IsCommercial")] Address address)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(address);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                } catch (DbUpdateException ex)
                {
                    if (ex.HResult == -2146233088)
                    {
                        ModelState.AddModelError("", @"Unable to save changes.
                                                       Address already exists");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                }
            }
            return(View(address));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,Creator,CreationDate")] Topic topic)
        {
            if (ModelState.IsValid)
            {
                var claimsIdentity = User.Identity as ClaimsIdentity;
                if (claimsIdentity != null)
                {
                    var userIdClaim = claimsIdentity.Claims
                                      .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

                    if (userIdClaim != null)
                    {
                        var userIdValue = userIdClaim.Value;
                        topic.Creator = userIdValue;
                    }
                }

                topic.Id = Guid.NewGuid();
                _context.Add(topic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Creator"] = new SelectList(_context.Users, "Id", "Id", topic.Creator);
            return(View(topic));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("Name,Description,UserID")] Department department)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(department);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                } catch (DbUpdateException ex)
                {
                    if (ex.HResult == -2146233088)
                    {
                        ModelState.AddModelError("", @"Unable to save changes.
                                                       Department already exists");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                }
            }
            ViewData["UserID"] = new SelectList(_context.User, "ID", "Name", department.UserID);
            return(View(department));
        }
Example #5
0
        public async Task <IActionResult> AddOrEdit([Bind("ManagerNotesId,Title,TextOfNote")] ManagerNote managerNote)
        {
            if (ModelState.IsValid)
            {
                if (managerNote.ManagerNotesId == 0)
                {
                    _context.Add(managerNote);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    _context.Update(managerNote);
                    await _context.SaveChangesAsync();

                    return(RedirectToRoute(new
                    {
                        controller = "ManagerNote",
                        action = "Index",
                        titleOfNote = managerNote.Title
                    }));
                }
            }
            return(View(managerNote));
        }
        public async Task <IActionResult> Create(
            [Bind("Name,Age,Email,Description")] User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            } catch (DbUpdateException ex)
            {
                if (ex.HResult == -2146233088)
                {
                    ModelState.AddModelError("", @"Unable to save changes.
                                                       User already exists");
                }
                else
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            return(View(user));
        }
Example #7
0
        public async Task <IActionResult> Create([Bind("Id,ProjectName,NumberOfWorkers")] Proekt proekt)
        {
            if (ModelState.IsValid)
            {
                _context.Add(proekt);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(proekt));
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("ManagerID,FirstName,LastName,Department")] Manager manager)
        {
            if (ModelState.IsValid)
            {
                _context.Add(manager);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(manager));
        }
        public async Task <IActionResult> Create([Bind("Name,Surname,Email")] Programist programist)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(programist);
                    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(programist));
        }