Exemplo n.º 1
0
        public IActionResult GetUserComplaints([FromBody] int userId)
        {
            try
            {
                if (userId != 0)
                {
                    var u = _serviceAppCompanySubjectIssue.Find(x => x.UserId == userId).Distinct().ToList();

                    u.Select(x =>
                    {
                        if (x.UserId == 0)
                        {
                            x.UserId = userId;
                        }
                        return(x);
                    }).ToList();

                    //u.Where(x => x.UserId == 0).ToList().ForEach(x => x.UserId = userId);

                    if (u != null)
                    {
                        var userSummary = new UserSummary();
                        userSummary.TotalOfComplaints = u.Count;
                        userSummary.ListCompanies     = u;

                        var result = _handleMessageUserSummary.Add(Application.Enum.HandleMessageType.Success, "List of complaints found!", userSummary);
                        return(Ok(result));
                    }
                    else
                    {
                        var result = _handleMessageUserSummary.Add(Application.Enum.HandleMessageType.Error, "List of complaints not found!", null);
                        return(Ok(result));
                    }
                }
                else
                {
                    var result = _handleMessageUserSummary.Add(Application.Enum.HandleMessageType.Error, "Problem to find a list of complaints!", null);
                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                var result = _handleMessageUserSummary.Add(Application.Enum.HandleMessageType.InternalErrors, "Something went wrong: !" + ex.ToString(), null);
                return(Ok(result));
            }
        }
Exemplo n.º 2
0
 public IActionResult GetSubjectIssue(string id)
 {
     try
     {
         var subjectIssues = _serviceAppSubjectIssue.Find(x => x.SubjectId == int.Parse(id)).ToList();
         if (subjectIssues.Count > 0)
         {
             var subjectIssueMapper = _mapper.Map <List <SubjectIssueDTO> >(subjectIssues);
             var result             = _handleMessageSubjectIssue.Add(Application.Enum.HandleMessageType.Success, "Subject found", subjectIssueMapper);
             return(Ok(result));
         }
         else
         {
             var result = _handleMessageSubjectIssue.Add(Application.Enum.HandleMessageType.Success, "Subject not found", null);
             return(Ok(result));
         }
     }
     catch (Exception ex)
     {
         var result = _handleMessageSubjectIssue.Add(Application.Enum.HandleMessageType.InternalErrors, "Something went wrong: !" + ex.ToString(), null);
         return(Ok(result));
     }
 }
Exemplo n.º 3
0
 public IActionResult GetSubject()
 {
     try
     {
         var subject = _serviceAppSubject.GetAll().ToList();
         if (subject.Count > 0)
         {
             var subjectMapper = _mapper.Map <List <SubjectDTO> >(subject);
             var result        = _handleMessageSubject.Add(Application.Enum.HandleMessageType.Success, "Subject found", subjectMapper);
             return(Ok(result));
         }
         else
         {
             var result = _handleMessageSubject.Add(Application.Enum.HandleMessageType.Success, "Subject not found", null);
             return(Ok(result));
         }
     }
     catch (Exception ex)
     {
         var result = _handleMessageSubject.Add(Application.Enum.HandleMessageType.InternalErrors, "Something went wrong: !" + ex.ToString(), null);
         return(Ok(result));
     }
 }
Exemplo n.º 4
0
        public IActionResult GetCompany(string searchTerm)
        {
            try
            {
                //generate fake data
                //var xCompany = new Helper.BogusFakeData(null, _serviceAppCompany, _serviceAppCompanyRate
                //    , _serviceAppCompanySubjectIssue, _mapper);
                //xCompany.CreateFakeCompanySubjectIssue(1000);

                if (!String.IsNullOrEmpty(searchTerm))
                {
                    var company = _serviceAppCompany.Find(x => x.CompanyName.ToUpper().Contains(searchTerm.ToUpper()))
                                  .Select(x => x).ToList();
                    if (company.Count > 0)
                    {
                        var companyMapper = _mapper.Map <List <CompanyDTO> >(company);
                        var result        = _handleMessageUser.Add(Application.Enum.HandleMessageType.Success, "Company found", companyMapper);
                        return(Ok(result));
                    }
                    else
                    {
                        var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.Success, "Company not found", null);
                        return(Ok(result));
                    }
                }
                else
                {
                    var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.Error, "Company was not find!", null);
                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.InternalErrors, "Something went wrong: !" + ex.ToString(), null);
                return(Ok(result));
            }
        }
Exemplo n.º 5
0
        public IActionResult SaveCompanyTellUs([FromBody] CompanySubjectTellUsDTO companySubjectTellUsDTO)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (companySubjectTellUsDTO.SubjectId != 0 && companySubjectTellUsDTO.SubjectIssueId != 0)
                    {
                        var companySubjectIssueTellUs = _mapper.Map <CompanySubjectIssue>(companySubjectTellUsDTO);
                        companySubjectIssueTellUs.DateAndTime = DateTime.Now;
                        _serviceAppCompanySubjectIssue.Add(companySubjectIssueTellUs);
                        var re = _handleMessageUser.Add(Application.Enum.HandleMessageType.Success, "Complaint registered successfully!", null);
                        return(Ok(re));
                    }
                    else
                    {
                        var subject      = _mapper.Map <Subject>(companySubjectTellUsDTO);
                        var subjectIssue = _mapper.Map <SubjectIssue>(companySubjectTellUsDTO);

                        var subId = _serviceAppSubject.Find(x => x.SubjectText.ToUpper().Equals(subject.SubjectText))
                                    .FirstOrDefault().Id;

                        var subIssueId = _serviceAppSubjectIssue.Find(x => x.SubjectIssueText.ToUpper().Equals(subjectIssue.SubjectIssueText))
                                         .FirstOrDefault().Id;

                        if (subId == 0 && subIssueId == 0)
                        {
                            subjectIssue.Subject = subject;
                            _serviceAppSubjectIssue.Add(subjectIssue);
                        }

                        companySubjectTellUsDTO.SubjectId      = subjectIssue.SubjectId;
                        companySubjectTellUsDTO.SubjectIssueId = subjectIssue.Id;

                        if (companySubjectTellUsDTO.CompanyId == 0)
                        {
                            var co = _serviceAppCompany.Find(x => x.CompanyName.ToUpper().Equals(companySubjectTellUsDTO.CompanyName)).FirstOrDefault();

                            if (co == null)
                            {
                                var company = _mapper.Map <Company>(companySubjectTellUsDTO);
                                _serviceAppCompany.Add(company);
                                companySubjectTellUsDTO.CompanyId = company.Id;

                                var companySubjectIssueTellUs = _mapper.Map <CompanySubjectIssue>(companySubjectTellUsDTO);
                                companySubjectIssueTellUs.DateAndTime = DateTime.Now;
                                _serviceAppCompanySubjectIssue.Add(companySubjectIssueTellUs);
                            }
                            else
                            {
                                companySubjectTellUsDTO.CompanyId = co.Id;

                                var companySubjectIssueTellUs = _mapper.Map <CompanySubjectIssue>(companySubjectTellUsDTO);
                                companySubjectIssueTellUs.DateAndTime = DateTime.Now;
                                _serviceAppCompanySubjectIssue.Add(companySubjectIssueTellUs);
                            }
                        }
                        else
                        {
                            companySubjectTellUsDTO.CompanyId = companySubjectTellUsDTO.CompanyId;
                            var companySubjectIssueTellUs = _mapper.Map <CompanySubjectIssue>(companySubjectTellUsDTO);

                            var companySubjectIssue = _serviceAppCompanySubjectIssue.Find(x => x.SubjectId == companySubjectIssueTellUs.SubjectId &&
                                                                                          x.SubjectIssueId == companySubjectIssueTellUs.SubjectIssueId && x.CompanyId == companySubjectIssueTellUs.CompanyId &&
                                                                                          x.UserId == companySubjectIssueTellUs.UserId).FirstOrDefault();

                            if (companySubjectIssue == null)
                            {
                                _serviceAppCompanySubjectIssue.Add(companySubjectIssueTellUs);
                            }
                            else
                            {
                                var result = _handleMessageCompanySubjectTellUs.Add(Application.Enum.HandleMessageType.Success, "Complaint already exists!", companySubjectTellUsDTO);
                                return(Ok(result));
                            }
                        }

                        var re = _handleMessageUser.Add(Application.Enum.HandleMessageType.Success, "Complaint registered successfully!", null);
                        return(Ok(re));
                    }
                }
                else
                {
                    var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.Error, "Problem to register your complaint!", null);
                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.InternalErrors, "Something went wrong: !" + ex.ToString(), null);
                return(Ok(result));
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> UserLogin([FromBody] UserLoginDTO user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //generate fake data
                    //var xUser = new BogusFakeData(_userManager, _serviceAppCompany, _serviceAppCompanyRate, _serviceAppCompanySubjectIssue, _mapper);
                    //xUser.CreateFakeCompanySubjectIssue(1000);

                    var u = await _userManager.Users.FirstOrDefaultAsync(x => x.Email.ToUpper().Equals(user.Email.ToUpper()) && x.Password.Equals(user.Password));

                    if (u != null)
                    {
                        ////verify if the password match the requirements.
                        //var outcome = await _signInManager.CheckPasswordSignInAsync(u, user.Password, false);

                        //if (outcome.Succeeded)
                        //{
                        var userToReturn = _mapper.Map <UserDTO>(u);
                        userToReturn.LastLogin     = DateTime.Now;
                        userToReturn.FacebookImage = false;
                        var update = await _userManager.UpdateAsync(u);

                        if (update.Succeeded)
                        {
                            var role = await _userManager.GetRolesAsync(u);

                            userToReturn.Roles = (List <string>)role;
                            return(Ok(new
                            {
                                token = GenerateJWToken(u).Result,
                                user = u,
                                Application.Enum.HandleMessageType.Success
                            }));
                        }
                        else
                        {
                            var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.Error, "Problem to log in!", null);
                            return(Ok(result));
                        }
                        //}
                        //else
                        //{
                        //    var result = _handleMessage.Add(Application.Enum.HandleMessageType.Error, "User does not exist!");
                        //    return Ok(result);
                        //}
                    }
                    else
                    {
                        var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.Error, "User does not exist!", null);
                        return(Ok(result));
                    }
                }
                else
                {
                    var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.Error, "Problem to log in!", null);
                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                var result = _handleMessageUser.Add(Application.Enum.HandleMessageType.InternalErrors, "Something went wrong: !" + ex.ToString(), null);
                return(Ok(result));
            }
        }