예제 #1
0
 public async Task <IActionResult> Put(int companyId, int mentorId, [FromBody] ExternalMentor mentor)
 {
     mentor.MentorID  = mentorId;
     mentor.CompanyID = companyId;
     if (!await _logic.Update(mentor))
     {
         return(BadRequest());
     }
     return(Ok());
 }
        public async Task <bool> Delete(long companyId, int mentorId)
        {
            ExternalMentor mentor = await _context.ExternalMentors
                                    .FirstOrDefaultAsync(x => x.CompanyID == companyId && x.MentorID == mentorId);

            if (mentor == null)
            {
                return(false);
            }
            _context.ExternalMentors.Remove(mentor);
            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> Insert(ExternalMentor mentor)
        {
            try
            {
                _context.ExternalMentors.Add(mentor);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(">>>>>>>>>>>" + ex.Message);
                return(false);
            }
        }
        public async Task <bool> Update(ExternalMentor mentor)
        {
            ExternalMentor m = await _context.ExternalMentors
                               .FirstOrDefaultAsync(p => p == mentor);

            if (m == null)
            {
                return(false);
            }
            m.Name    = mentor.Name;
            m.Surname = mentor.Surname;
            //m.Contacts = mentor.Contacts;
            _context.ExternalMentors.Update(m);
            await _context.SaveChangesAsync();

            return(true);
        }