Beispiel #1
0
        public ServiceData.Models.Study Insert(ServiceData.Models.Study s)
        {
            try
            {
                Study result = context.Studies.Add(new Study
                {
                    Active    = s.Active,
                    CreatedAt = s.CreatedAt,
                    Code      = s.Code,
                    Name      = s.Name,
                    ManagerId = s.ManagerId
                });

                if (s.Manager != null)
                {
                    result.Manager = context.Users.FirstOrDefault(c => c.Id == s.Manager.Id);
                }

                context.SaveChanges();
                s.Id = result.Id;
                return(s);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public ServiceData.Models.Share Insert(ServiceData.Models.Share model)
        {
            try
            {
                Share result = context.Shares.Add(new Share
                {
                    Id          = model.Id,
                    CreatedAt   = model.CreatedAt,
                    ExpireDate  = model.ExpireDate,
                    OwnerId     = model.Owner.Id,
                    Updated     = model.Updated,
                    SharedEmail = model.SharedEmail
                });

                if (model.UserCondition != null)
                {
                    result.UserCondition = context.UserConditions.FirstOrDefault(c => c.Id == model.UserCondition.Id);
                }

                context.SaveChanges();
                model.Id = result.Id;
                return(model);
            }
            catch
            {
                return(null);
            }
        }
        public ServiceData.Models.EventLog Insert(ServiceData.Models.EventLog model)
        {
            EventLog log = context.EventLogs.Add(new EventLog
            {
                Action    = model.Action,
                CreatedAt = model.CreatedAt,
                UserId    = model.UserId
            });

            context.SaveChanges();

            model.Id = log.Id;

            return(model);
        }
Beispiel #4
0
        public ServiceData.Models.Photo Insert(ServiceData.Models.Photo model)
        {
            try
            {
                Photo result = context.Photos.Add(new Photo
                {
                    Notes            = model.Notes,
                    CreatedAt        = model.CreatedAt,
                    PhotoDescription = model.PhotoDescription,
                    Rating           = model.Rating,
                    Treatment        = model.Treatment,
                    Url             = model.Url,
                    ThumbUrl        = model.ThumbUrl,
                    UserConditionId = model.UserCondition.Id,
                });

                context.SaveChanges();

                result.UserCondition = new UserCondition
                {
                    Id        = model.UserCondition.Id,
                    Condition = model.UserCondition.Condition,
                    Owner     = new User
                    {
                        Id        = model.UserCondition.Owner.Id,
                        Name      = model.UserCondition.Owner.Name,
                        Email     = model.UserCondition.Owner.Email,
                        BirthDate = model.UserCondition.Owner.BirthDate
                    },
                    OwnerId    = model.UserCondition.Owner.Id,
                    Passcode   = model.UserCondition.Passcode,
                    SkinRegion = new SkinRegion
                    {
                        Id   = model.UserCondition.SkinRegion.Id,
                        Name = model.UserCondition.SkinRegion.Name
                    }
                };

                return(ToServiceModel(result));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        ServiceData.Models.UserCondition IReadWriteRepository <ServiceData.Models.UserCondition> .Insert(ServiceData.Models.UserCondition model)
        {
            try
            {
                UserCondition result = context.UserConditions.Add(new UserCondition
                {
                    Condition    = model.Condition,
                    OwnerId      = model.Owner.Id,
                    SkinRegionId = model.SkinRegion.Id,
                    Passcode     = model.Passcode,
                    StartDate    = model.StartDate,
                    Finished     = model.Finished,
                    Treatment    = model.Treatment
                });

                context.SaveChanges();

                result.SkinRegion = new SkinRegion
                {
                    Id         = model.SkinRegion.Id,
                    Name       = model.SkinRegion.Name,
                    BodyPartId = model.SkinRegion.BodyPart.Id,
                    BodyPart   = new BodyPart
                    {
                        Id   = model.SkinRegion.BodyPart.Id,
                        Name = model.SkinRegion.BodyPart.Name
                    }
                };

                result.Owner = new User
                {
                    Id        = model.Owner.Id,
                    Name      = model.Owner.Name,
                    Email     = model.Owner.Email,
                    BirthDate = model.Owner.BirthDate
                };

                return(ToServiceModel(result));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Beispiel #6
0
        public ServiceData.Models.StudyEnrolment Insert(ServiceData.Models.StudyEnrolment s)
        {
            try
            {
                StudyEnrolment result = context.StudyEnrolments.Add(new StudyEnrolment
                {
                    CreatedAt = s.CreatedAt,
                    Enrolled  = s.Enrolled,
                    StudyId   = s.StudyId,
                    UserId    = s.UserId
                });

                context.SaveChanges();

                s.Id = result.Id;
                return(s);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }