public async Task <IActionResult> CreateTask(UserTask task)
        {
            if (ModelState.IsValid)
            {
                var      user    = _userManager.Users.Where(x => x.UserName == HttpContext.User.Identity.Name).First();
                UserTask newTask = new UserTask
                {
                    Title       = task.Title,
                    Description = task.Description,
                    CreatedDate = DateTime.Now,
                    ExpireDate  = task.ExpireDate,
                    AppUserId   = user.Id
                };

                _db.Tasks.Add(newTask);

                _db.Shares.Add(new UserTaskRelation()
                {
                    AppUserId  = user.Id,
                    UserTaskId = newTask.Id
                });

                await _db.SaveChangesAsync();

                return(RedirectToAction(actionName: "Index", controllerName: "Home"));
            }
            else
            {
                ModelState.AddModelError("", "This task don't created");
                return(View(task));
            }
        }
Exemple #2
0
        public async Task <ApiResponse <long> > QueueAsync(string clientName, SendEmailRequest request)
        {
            var trail = new EmailTrail
            {
                RequestOrigin = clientName,
                Status        = EmailStatus.RequestReceived
            };

            try
            {
                await _emails.AddAsync(trail);

                await _dbContext.SaveChangesAsync();

                var dto     = BuildDto(trail.Id, request);
                var success = SendToQueue(dto);

                if (success)
                {
                    _logger.LogInformation("Email added to queue (ID {id})", dto.Id);
                    trail.Status          = EmailStatus.InQueue;
                    trail.UpdatedDateTime = DateTime.UtcNow;
                }
                else
                {
                    _logger.LogWarning("Failed to add email to queue; client: {client}", clientName);
                    _logger.LogInformation("Saving email data to database (ID {id})...", dto.Id);
                    trail.Status          = EmailStatus.FailedToQueue;
                    trail.UpdatedDateTime = DateTime.UtcNow;
                    trail.Failed          = new Failed
                    {
                        Receiver        = dto.Receiver,
                        Sender          = dto.Sender,
                        Subject         = dto.Subject,
                        Body            = dto.Body,
                        CreatedDateTime = DateTime.UtcNow,
                    };
                }

                _emails.Update(trail);
                await _dbContext.SaveChangesAsync();

                return(new ApiResponse <long>(trail.Id));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception caught while trying to process a request from client {0}; email trail ID: {1}", clientName, trail.Id);
                return(new ApiResponse <long>(new Error(ErrorCode.UnhandledException)));
            }
        }
Exemple #3
0
 public void Add()
 {
     using (EmailDbContext db = new EmailDbContext())
     {
         try
         {
             Email email = new Email()
             {
                 F_Name    = firstname,
                 L_Name    = lastname,
                 Email_Add = emailaddress,
                 Eml_Id    = emailid,
                 U_Id      = userid
             };
             db.Emails.Add(email);
             db.SaveChangesAsync();
             ProecessSuccess?.Invoke(null, null);
         }
         catch (Exception ex)
         {
             ProcessFailDelegate Failed = ProcessFail;
             Failed?.Invoke("Failed" + Environment.NewLine + ex.ToString());
         }
     }
 }
        public async Task <Email> Save(IMailChangedMessage email)
        {
            var entity = new Email()
            {
                Body    = email.EmailDto.Body,
                Id      = new Guid(),
                Subject = email.EmailDto.Subject,
                To      = email.EmailDto.To
            };
            await _emailDbContext.Emails.AddAsync(entity);

            await _emailDbContext.SaveChangesAsync();

            return(entity);
        }
Exemple #5
0
 public void Delete()
 {
     using (EmailDbContext db = new EmailDbContext())
     {
         try
         {
             Email email = db.Emails.Where(x => x.U_Id == userid && x.Eml_Id == emailid).FirstOrDefault();
             db.Emails.Remove(email);
             db.SaveChangesAsync();
             ProecessSuccess?.Invoke(null, null);
         }
         catch (Exception ex)
         {
             ProcessFailDelegate Failed = ProcessFail;
             Failed?.Invoke("Failed" + Environment.NewLine + ex.ToString());
         }
     }
 }
Exemple #6
0
        public async Task <IActionResult> Create(EmailDTO emailData)
        {
            var email = _mapper.Map <Email>(emailData);

            _dbContext.Emails.Add(email);
            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
            return(Ok(email.Id));
        }