public async Task AddCaseAsync(string email, CreateCase @case)
        {
            User user = await _userRepository.GetByEmailAsync(email);

            if (user != null)
            {
                Case new_case = new Case(@case.Title, email, @case.Type, @case.Description, _mapper.Map <IEnumerable <Document> >(@case.Documents));
                user.AddCase(new_case);
                await _userRepository.UpdateAsync(user);
            }
        }
        public async Task <ActionResult> UpdateCase(string email, [FromBody] CreateCase newCase)
        {
            UserDTO user = await _userService.GetByEmailAsync(email);

            if (user == null)
            {
                await _userService.RegisterAsync(new CreateUser()
                {
                    Email = email
                }, "unregistered");
            }

            await _userService.AddCaseAsync(email, newCase);

            return(Created("/cases", null));
        }
        public async Task SendEmailAsync(string sender_email, CreateCase @case)
        {
            SmtpClient client = new SmtpClient
            {
                DeliveryMethod = SmtpDeliveryMethod.Network,
                EnableSsl      = true,
                Host           = "smtp.gmail.com",
                Port           = 587
            };

            System.Net.NetworkCredential credentials =
                new System.Net.NetworkCredential("*****@*****.**", "haslo4321");
            client.UseDefaultCredentials = false;
            client.Credentials           = credentials;

            MailMessage message = new MailMessage
            {
                From = new MailAddress("*****@*****.**")
            };

            StringBuilder documents = new StringBuilder();

            if (@case.Documents == null)
            {
                documents.Append("Ta sprawa nie posiada żadnych dodanych dokumentów.");
            }
            else
            {
                foreach (SendDocument document in @case.Documents)
                {
                    documents.Append($"<li><span class=\"text\"><a href=\"{document.Url}\">{document.Name}</a></span></li>");
                }
            }

            message.Subject    = "System obsługi dokumentów";
            message.IsBodyHtml = true;
            message.Body       = string.Format($"<html><head></head><body><table><tr><td valign = \"top\" width= \"33.333%\" style= \"padding-top: 20px;\"><table role= \"presentation\" cellspacing= \"0\" cellpadding= \"0\" border= \"0\" width= \"100%\"><tr><td style= \"text-align: left; padding-left: 5px; padding-right: 5px;\"><h3 class=\"heading\">Użytkownik o adresie e-mail {sender_email} dodał nową sprawę o treści:</h3>{@case.Description}<h4 class=\"heading\">Lista dokumentów:</h4><ul>{documents.ToString()}</ul></td></tr></table></body></head>");
            client.Send(message);

            await Task.CompletedTask;
        }
        public async Task <ActionResult> PostCase([FromBody] CreateCase @case, string email)
        {
            await _userService.AddCaseAsync(email, @case);

            return(Created("/cases", null));
        }
예제 #5
0
        public OperationResponse <CaseDto> Post(CreateCase request)
        {
            OperationResponse <CaseDto> operationResponse = new OperationResponse <CaseDto>();

            ClientValidator          clientValidator          = new ClientValidator();
            CaseInformationValidator caseInformationValidator = new CaseInformationValidator();
            NotesValidator           notesValidator           = new NotesValidator();

            CaseInformationDto      caseInformation = request.CaseDto.CaseInformation;
            ClientDto               client          = request.CaseDto.Client;
            NotesDto                notes           = request.CaseDto.Notes;
            CaseStatusDto           caseStatus      = request.CaseDto.CaseStatus;
            List <CaseReferenceDto> references      = request.CaseDto.References;
            List <string>           errors          = new List <string>();

            ValidationResult validationResult = clientValidator.Validate(client);

            if (!validationResult.IsValid)
            {
                ;
                foreach (var error in validationResult.Errors)
                {
                    errors.Add(error.ErrorMessage);
                }
            }

            validationResult = caseInformationValidator.Validate(caseInformation);
            if (!validationResult.IsValid)
            {
                foreach (var error in validationResult.Errors)
                {
                    errors.Add(error.ErrorMessage);
                }
            }

            validationResult = notesValidator.Validate(notes);
            if (!validationResult.IsValid)
            {
                foreach (var error in validationResult.Errors)
                {
                    errors.Add(error.ErrorMessage);
                }
            }

            if (errors.Count != 0)
            {
                operationResponse.OnError("Invalid input data", errors);
                return(operationResponse);
            }

            try
            {
                CaseDto caseDto = CaseBusinessLogic.AddNewCase(client, caseInformation, notes, caseStatus, references);
                operationResponse.OnSuccess(caseDto, "Added successfully");
                return(operationResponse);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                operationResponse.OnException(e.Message);
                return(operationResponse);
            }
        }