Exemplo n.º 1
0
        public GeneralResponse EditEmail(EditEmailRequest request)
        {
            GeneralResponse response = new GeneralResponse();
            Email           email    = new Email();

            email = _emailRepository.FindBy(request.ID);

            if (email != null)
            {
                try
                {
                    email.ModifiedDate     = PersianDateTime.Now;
                    email.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (request.Body != null)
                    {
                        email.Body = request.Body;
                    }
                    if (request.CustomerID != null)
                    {
                        email.Customer = this._customerRepository.FindBy(request.CustomerID);
                    }
                    email.Sent = request.Sent;
                    if (request.Subject != null)
                    {
                        email.Subject = request.Subject;
                    }
                    if (request.Note != null)
                    {
                        email.Note = request.Note;
                    }

                    if (email.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        email.RowVersion += 1;
                    }

                    if (email.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in email.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    _emailRepository.Save(email);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
Exemplo n.º 2
0
 public List <EmailMessage> Invoke(int count)
 {
     return(emailRepository.FindBy(x => x.Message != null).Take(count).ToList());
 }