public async Task <IActionResult> PutInternship(int id, InternshipDTO internshipDTO)
        {
            if (id != internshipDTO.Id)
            {
                return(BadRequest());
            }

            var internship = await _context.Internships.FindAsync(id);

            if (internship == null)
            {
                return(NotFound());
            }

            internship.Title       = internshipDTO.Title;
            internship.Description = internshipDTO.Description;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!InternshipExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
示例#2
0
 public bool Delete(InternshipDTO internship)
 {
     using (var ctx = new Utn_SysContext())
     {
         ctx.Interships.Remove(_mapper.Map <Interships>(internship));
         ctx.SaveChanges();
         return(true);
     }
 }
示例#3
0
        public IActionResult Post([FromBody] InternshipDTO internship)
        {
            try
            {
                var Id = HttpContext.User.Claims.Where(x => x.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value;

                return(Ok(internshipService.CreateOrUpdate(internship, Id)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <ActionResult <InternshipDTO> > PostInternship(InternshipDTO internshipDTO)
        {
            var internship = new Internship
            {
                Title       = internshipDTO.Title,
                Description = internshipDTO.Description,
            };

            _context.Internships.Add(internship);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetInternship),
                       new { id = internship.Id },
                       InternshipToDTO(internship)));
        }
示例#5
0
        public bool CreateOrUpdate(InternshipDTO internship, int userId)
        {
            try
            {
                using (var ctx = new Utn_SysContext())
                {
                    var oInternship = ctx.Interships.AsNoTracking()
                                      .Where(c => c.Id == internship.Id)
                                      .FirstOrDefault();

                    if (oInternship == null)
                    {
                        oInternship = new Interships();
                        ctx.Interships.Add(oInternship);
                        oInternship.CreatedDate   = DateTime.Now;
                        oInternship.State         = "Nueva";
                        oInternship.UserCreatedId = userId;
                    }
                    else
                    {
                        ctx.Interships.Attach(oInternship);
                        oInternship.LastModified      = DateTime.Now;
                        oInternship.UserLasModifiedId = userId;
                    }
                    oInternship.DailyHours           = internship.DailyHours;
                    oInternship.WorkAgreement        = internship.WorkAgreement;
                    oInternship.CompanyTutorId       = internship.CompanyMentorId;
                    oInternship.CompanySignatory     = internship.CompanySignatory;
                    oInternship.SalaryWorkAssignment = internship.SalaryWorkAssignment;
                    oInternship.StartDate            = internship.StartDate;
                    oInternship.EndDate         = internship.EndDate;
                    oInternship.StudentId       = internship.StudentId;
                    oInternship.TaskDescription = internship.TaskDescription;
                    oInternship.CompanyId       = internship.CompanyId;
                    oInternship.Observations    = internship.Observations;

                    ctx.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#6
0
 public bool Delete(InternshipDTO internship)
 {
     return(internshipRepo.Delete(internship));
 }
示例#7
0
 public bool CreateOrUpdate(InternshipDTO internship, string userId)
 {
     return(internshipRepo.CreateOrUpdate(internship, int.Parse(userId)));
 }