public IActionResult AddConsultant([FromBody] ConsultantsViewModel consultantViewModel)
        {
            try
            {
                var        userId     = IdentityHelper.GetUserId(HttpContext);
                Consultant consultant = Mapper.Map <ConsultantsViewModel, Consultant>(consultantViewModel);

                consultant.UserId       = userId;
                consultant.IsApproved   = 0;
                consultant.CreationDate = DateTime.Now;
                consultant.LastUpdate   = DateTime.Now;
                consultant.ReminderDate = DateTime.Now.AddMonths(1);

                _consultantsRepository.AddConsultant(consultant);

                string content = "A new consultant listing has been added\n" +
                                 "\nID: " + consultant.ConsultantId +
                                 "\nConsultant name: " + consultant.FirstName + " " + consultant.LastName +
                                 "\n\nPlease go to https://capstone1.azurewebsites.net/admin to approve this consultant listing";
                string subject = "New consultant listing";

                _emailService.SendToAdmins(subject, content);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public void EditConsultant(ConsultantsViewModel consultant)
        {
            Consultant oldConsultant = GetConsultantById(consultant.ConsultantId.Value);

            _context.Consultants.Attach(oldConsultant);

            oldConsultant.LastUpdate     = DateTime.Now;
            oldConsultant.ReminderDate   = DateTime.Now.AddMonths(1);
            oldConsultant.FirstName      = consultant.FirstName;
            oldConsultant.LastName       = consultant.LastName;
            oldConsultant.ImageURL       = consultant.ImageURL;
            oldConsultant.SpecialistArea = consultant.SpecialistArea;
            oldConsultant.ConsultantDesc = consultant.ConsultantDesc;
            oldConsultant.Phone          = consultant.Phone;
            oldConsultant.Email          = consultant.Email;
            oldConsultant.Website        = consultant.Website;
            oldConsultant.Address1       = consultant.Address1;
            oldConsultant.Address2       = consultant.Address2;
            oldConsultant.Suburb         = consultant.Suburb;
            oldConsultant.PostalCode     = consultant.PostalCode;
            oldConsultant.City           = consultant.City;
            oldConsultant.Country        = consultant.Country;

            _context.SaveChanges();
        }
 public IActionResult EditConsultant([FromBody] ConsultantsViewModel consultant)
 {
     try
     {
         if (consultant.ConsultantId.HasValue)
         {
             if (_consultantsRepository.GetUserId(consultant.ConsultantId.Value) == IdentityHelper.GetUserId(HttpContext))
             {
                 _consultantsRepository.EditConsultant(consultant);
                 return(Ok());
             }
             else
             {
                 return(Unauthorized());
             }
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }