예제 #1
0
 public void AddOrUpdateUser(User user)
 {
     using (var context = new CleanCityContext())
     {
         var sqlUser = context.Users.SingleOrDefault(x => x.UserId == user.UserId);
         if (sqlUser == null)
         {
             context.Users.Add(new UserSql
             {
                 Email    = user.Email,
                 UserId   = user.UserId,
                 Address  = user.Address,
                 Username = user.Username,
             });
             context.SaveChanges();
         }
         else
         {
             sqlUser.Email    = user.Email;
             sqlUser.Username = user.Username;
             sqlUser.Address  = user.Address;
             context.Update(sqlUser);
             context.SaveChanges();
         }
     }
 }
예제 #2
0
        public Guid AddResponsible(Responsible responsible)
        {
            using (var context = new CleanCityContext())
            {
                // todo(sivukhin, 18.05.2019): Fix data race here
                var sqlResponsible = context.ResponsibleList.SingleOrDefault(x => x.Id == responsible.Id);
                if (sqlResponsible != null)
                {
                    sqlResponsible.Name           = responsible.Name;
                    sqlResponsible.Email          = responsible.Email;
                    sqlResponsible.ResponseRegion = responsible.ResponseRegion;
                    context.Update(sqlResponsible);
                }
                else
                {
                    context.ResponsibleList.Add(new ResponsibleSql
                    {
                        Id             = responsible.Id,
                        Name           = responsible.Name,
                        Email          = responsible.Email,
                        IsActive       = responsible.IsActive,
                        ResponseRegion = responsible.ResponseRegion,
                    });
                }

                context.SaveChanges();
                return(responsible.Id);
            }
        }
예제 #3
0
 public void SetEmailProcessed(Guid emailId)
 {
     using (var context = new CleanCityContext())
     {
         var email = context.Emails.SingleOrDefault(e => e.Id == emailId);
         if (email == null)
         {
             return;
         }
         email.IsSent = true;
         context.Emails.Update(email);
         context.SaveChanges();
     }
 }
예제 #4
0
 public Guid AddEmail(EmailMessage email)
 {
     using (var context = new CleanCityContext())
     {
         var id = Guid.NewGuid();
         context.Emails.Add(new EmailMessageSql
         {
             Id            = id,
             ResponsibleId = email.ResponsibleId,
             Data          = SerializeEmail(email),
             IsSent        = false,
         });
         context.SaveChanges();
         return(id);
     }
 }
예제 #5
0
 public Guid AddReport(Report report)
 {
     using (var context = new CleanCityContext())
     {
         var reportId = Guid.NewGuid();
         context.Reports.Add(new ReportSql
         {
             Id            = reportId,
             UserId        = report.UserId,
             Body          = report.ReportText,
             CreationDate  = report.CreationDate,
             Subject       = report.Subject,
             Location      = new NpgsqlPoint(report.Location.Latitude, report.Location.Longitude),
             ResponsibleId = report.ResponsibleId,
             Payload       = SerializeReport(report),
         });
         context.SaveChanges();
         return(reportId);
     }
 }
예제 #6
0
 public void AddDoubler(Guid responsibleId, Responsible doubler)
 {
     using (var context = new CleanCityContext())
     {
         var responsible = context.ResponsibleList.SingleOrDefault(x => x.Id == responsibleId);
         if (responsible == null)
         {
             return;
         }
         var sqlDoubler = new ResponsibleDoublerSql
         {
             Id    = Guid.NewGuid(),
             Name  = doubler.Name,
             Email = doubler.Email,
             OriginalResponsible = responsible
         };
         if (responsible.DoublerList == null)
         {
             responsible.DoublerList = new List <ResponsibleDoublerSql>();
         }
         responsible.DoublerList.Add(sqlDoubler);
         context.SaveChanges();
     }
 }