public async Task <IActionResult> PutInternship(int id, InternshipModel internshipModel)
        {
            //if (id != internship.InternshipId)
            //{
            //    return BadRequest();
            //}
            try
            {
                var User_id = _customAuthManager.Tokens.FirstOrDefault().Value.Item3;

                // ToDO-> get User ID from Session
                User       user       = _context.Users.Find(User_id);
                Internship internship = new Internship();
                // SetAddorUpdateIntern(Intership - TYPE, User =TYPE, Bool -TYPE)
                // the above method fill the object with user provided values and bool if it is for update
                internship.SetAddorUpdateIntern(internshipModel, user, true, id);
                _context.Internships.Update(internship);
                _context.SaveChanges();
                return(Ok(internship));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
예제 #2
0
        public void Update(int id, [FromBody] InternshipModel value)
        {
            var existingInternship = internships.Find(id);

            if (existingInternship != null)
            {
                existingInternship.Name = value.Name;
                existingInternship.Year = value.Year;
                db.SaveChanges();
            }
        }
예제 #3
0
        public async Task <ActionResult <InternshipModel> > AddInternship(InternshipModel model)
        {
            try
            {
                var internship = _mapper.Map <Internship>(model);
                var result     = await _repository.AddInternship(internship);

                if (result == null)
                {
                    return(NotFound("Internship could not be saved"));
                }

                return(_mapper.Map <InternshipModel>(result));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database failure"));
            }
        }
예제 #4
0
 public JsonResult UpdateInternship(InternshipModel model)
 {
     try
     {
         var result   = CorporateBusiness.UpdateInternship(model);
         var response = new ApiRespnoseWrapper {
             status = ApiRespnoseStatus.Success, results = new ArrayList()
             {
                 result
             }
         };
         return(new JsonResult {
             Data = response
         });
     }
     catch (Exception ex)
     {
         return(CommonBusiness.GetErrorResponse(ex.Message));
     }
 }
        public ActionResult <Internship> PostInternship(InternshipModel newInternship)
        {
            try
            {
                var id = _customAuthManager.Tokens.FirstOrDefault().Value.Item3;

                // ToDO-> get User ID from Session
                User       user       = _context.Users.Find(id);
                Internship internship = new Internship();
                // SetAddorUpdateIntern(Intership - TYPE, User =TYPE, Bool -TYPE)
                // the above method fill the object with user provided values and bool if it is for update
                internship.SetAddorUpdateIntern(newInternship, user);
                _context.Internships.Add(internship);
                _context.SaveChanges();
                return(Ok(internship));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
예제 #6
0
        }                                      // Poster


        public void SetAddorUpdateIntern(InternshipModel intern, User user, bool isUpdate = false, int InternshipID = 0)
        {
            this.InternshipTitle    = intern.InternshipTitle;
            this.InternshipType     = intern.InternshipType;
            this.InternshipDuration = intern.InternshipDuration;
            this.InternshipBody     = intern.InternshipBody;
            this.InternshipVirtual  = intern.InternshipVirtual;
            this.InternshipPaid     = intern.InternshipPaid;
            this.InternshipEmail    = intern.InternshipEmail;
            this.InternshipExpDate  = intern.InternshipExpDate;
            if (isUpdate && InternshipID != 0)
            {
                this.InternshipId        = InternshipID;
                this.InternshipUpdatedAt = DateTime.Now;
            }
            else
            {
                this.InternshipCreatedAt = DateTime.Now;
            }

            this.User = user;
        }
예제 #7
0
 public static Internship InternshipModelToInternship(InternshipModel value)
 {
     return(new Internship {
         Id = value.Id, Name = value.Name, Year = value.Year
     });
 }
예제 #8
0
 public void Add([FromBody] InternshipModel value)
 {
     internships.Add(InternshipConverter.InternshipModelToInternship(value));
     db.SaveChanges();
 }