Example #1
0
        public async Task <IActionResult> PutProject(int id, Project project)
        {
            if (id != project.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #2
0
        //public async Task<IActionResult> Create([Bind("ID,Name,Content,Price,CreatedAt,UpdatedAt")] Project project)
        public async Task <IActionResult> Create([Bind("ID,Name,Content,Price,Image")] ProjectCreate projectCreate)
        {
            Project projectModel = null;

            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(projectCreate);
                string fileLocation   = HttpContext.Request.Scheme + "://" + this.Request.Host + "/images/" + uniqueFileName;

                projectModel = new Project
                {
                    Name    = projectCreate.Name,
                    Content = projectCreate.Content,
                    Price   = projectCreate.Price,
                    //Picture = uniqueFileName,
                    Picture = fileLocation,
                };

                _context.Add(projectModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(projectModel));
        }
Example #3
0
        public async Task <IActionResult> PutTask(int id, Education.Models.Task task)
        {
            if (id != task.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #4
0
        //public async Task<IActionResult> Create([Bind("ID,Title,Note,Video,Header,Tag,ProjectId,CreatedAt,UpdatedAt")] Education.Models.Task task)
        public async Task <IActionResult> Create([Bind("ID,Title,Note,Video,Header,Tag,ProjectId")] Education.Models.Task task)
        {
            if (ModelState.IsValid)
            {
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectId"] = new SelectList(_context.Project, "ID", "ID", task.ProjectId);
            return(View(task));
        }
Example #5
0
        public async Task <IActionResult> UpdateMajor(int id, Major major)
        {
            if (id != major.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #6
0
        public async Task <bool> CommitAsync()
        {
            bool returnValue = true;

            using (var dbContextTransaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    //yeni kayıt(lar) atılırken; recordDate şuanki tarih atılıyor
                    var addedEntities = _dbContext.ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();

                    addedEntities.ForEach(E =>
                    {
                        E.Property(nameof(BaseEntity.RecordDate)).CurrentValue = DateTime.Now;
                    });

                    //güncelleme yapılan kayıt(lar)'da; updateDate kolonuna suanki tarih verisi atılıyor
                    var editedEntities =
                        _dbContext.ChangeTracker.Entries().Where(e => e.State == EntityState.Modified).ToList();

                    editedEntities.ForEach(e =>
                    {
                        e.Property(nameof(BaseEntity.UpdateDate)).CurrentValue = DateTime.Now;
                    });

                    await _dbContext.SaveChangesAsync();

                    await dbContextTransaction.CommitAsync();
                }
                catch (Exception)
                {
                    //Log Exception Handling message
                    returnValue = false;
                    await dbContextTransaction.RollbackAsync();
                }
            }

            return(returnValue);
        }
Example #7
0
            public async Task <Unit> Handle(CreateCursoCommandRequest request, CancellationToken cancellationToken)
            {
                var curso = new Curso
                {
                    CursoId          = Guid.NewGuid(),
                    Titulo           = request.Titulo,
                    Descripcion      = request.Descripcion,
                    FechaCreacion    = DateTime.Now,
                    FechaPublicacion = request.FechaPublicacion,
                    Precio           = request.Precio,
                };

                await _context.AddAsync(curso);

                var valor = await _context.SaveChangesAsync();

                if (valor > 0)
                {
                    return(Unit.Value);
                }

                throw new Exception("No se pudo insertar el curso");
            }