Exemplo n.º 1
0
        /// <summary>
        /// Saves the specified schedule.
        /// </summary>
        /// <param name="schedule">The schedule.</param>
        /// <returns>Changed schedule.</returns>
        public ScheduMail.Core.Domain.Schedule Save(ScheduMail.Core.Domain.Schedule schedule)
        {
            ScheduMail.DBModel.Schedule entity =
                ObjectExtension.CloneProperties<ScheduMail.Core.Domain.Schedule, ScheduMail.DBModel.Schedule>(schedule);



            if (schedule.IsNew())
            {
                entity.Mail = (from w in this.context.Mails
                               where w.Id == schedule.MailId
                               select w).FirstOrDefault();
                this.context.AddToSchedules(entity);
                this.context.SaveChanges();
            }
            else
            {
                var originalWebSite = (from w in this.context.Schedules
                                       join mails in this.context.Mails on
                                       schedule.MailId equals mails.Id
                                       where w.Id == schedule.Id
                                       select w).First();

                this.context.ApplyPropertyChanges(originalWebSite.EntityKey.EntitySetName, entity);
                this.context.SaveChanges();
            }

            return ObjectExtension.CloneProperties<ScheduMail.DBModel.Schedule, ScheduMail.Core.Domain.Schedule>(entity);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the specified web site.
        /// </summary>
        /// <param name="schedules">The schedule.</param>
        public void Delete(ScheduMail.Core.Domain.Schedule schedules)
        {
            var entity = (from w in this.context.Schedules
                          where w.Id == schedules.Id
                          select w).First();

            this.context.DeleteObject(entity);
            this.context.SaveChanges();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Saves the specified web site.
 /// </summary>
 /// <param name="schedule">The web site.</param>
 /// <returns>Updated Web site instance.</returns>
 public ScheduMail.Core.Domain.Schedule Save(ScheduMail.Core.Domain.Schedule schedule)
 {
     var errors = this.GetRuleViolations(schedule);
     if (errors.Count > 0)
     {
         throw new RuleException(errors);
     }
     return this.repository.Save(schedule);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Saves the specified users.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="isAdministrator">if set to <c>true</c> [is administrator].</param>
        /// <param name="selectedWebSites">The selected web sites.</param>
        /// <returns>Updated user instance.</returns>
        public ScheduMail.Core.Domain.AspnetUsers Save(ScheduMail.Core.Domain.AspnetUsers users, bool isAdministrator, string[] selectedWebSites)
        {
            var errors = this.GetRuleViolations(users);
            if (errors.Count > 0)
            {
                throw new RuleException(errors);
            }

            return this.repository.Save(users, isAdministrator, selectedWebSites);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves the specified web site.
        /// </summary>
        /// <param name="webSite">The web site.</param>
        /// <returns>Changed web site.</returns>
        public ScheduMail.Core.Domain.WebSite Save(ScheduMail.Core.Domain.WebSite webSite)
        {
            ScheduMail.DBModel.WebSite entity =
                ObjectExtension.CloneProperties<ScheduMail.Core.Domain.WebSite, ScheduMail.DBModel.WebSite>(webSite);

            if (webSite.IsNew())
            {
                this.context.AddToWebSites(entity);
                this.context.SaveChanges();
            }
            else
            {
                var originalWebSite = (from w in this.context.WebSites
                                       where w.Id == webSite.Id
                                       select w).First();

                this.context.ApplyPropertyChanges(originalWebSite.EntityKey.EntitySetName, entity);
                this.context.SaveChanges();
            }

            return ObjectExtension.CloneProperties<ScheduMail.DBModel.WebSite, ScheduMail.Core.Domain.WebSite>(entity);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Saves the specified user.
        /// </summary>
        /// <param name="user">The user instance.</param>
        /// <param name="isAdministrator">if set to <c>true</c> [is administrator].</param>
        /// <param name="selectedWebSites">The selected web sites.</param>
        /// <returns>Saved user instance.</returns>
        public ScheduMail.Core.Domain.AspnetUsers Save(ScheduMail.Core.Domain.AspnetUsers user, bool isAdministrator, string[] selectedWebSites)
        {
            //ensure the username has not already been used
            MembershipUser memberShipUser = Membership.GetUser(user.Username);
            if (memberShipUser != null)
            {
                throw new RuleException("Username", "Username already exists, please specify a different username");
            }

            //ensure the email address has not already been used
            bool emailExists = !string.IsNullOrEmpty(Membership.GetUserNameByEmail(user.Email));
            if (emailExists)
            {
                throw new RuleException("Email", "Email address already exists, please specify a different email address");
            }

            //create user and populate membership to update website/ admin details
            memberShipUser = Membership.CreateUser(user.Username, user.Password, user.Email);

            // Next read existing user and associated website records (website records reflect many-to- many relationship between
            // usr and web sites.
            ScheduMail.DBModel.aspnet_Users entityUser =
                this.context.aspnet_Users.Include("WebSite")
                .Where(q => q.Username == memberShipUser.UserName).First();

            entityUser.Email = user.Email;

            // Clean up any existing website associations.
            int count = entityUser.WebSite.Count;
            for (int i = 0; i < count; i++)
            {
                entityUser.WebSite.Remove(entityUser.WebSite.ElementAt(0));
            }
           
            // if there are any website associations to add
            // associate websites with user. Note will add entries to userwebsite.
            if (selectedWebSites != null)
            {
                foreach (string website in selectedWebSites)
                {
                    long entityWebSiteId = Convert.ToInt64(website);
                    ScheduMail.DBModel.WebSite entityWebSite = this.context.WebSites.Where(q => q.Id == entityWebSiteId).First();
                    entityUser.WebSite.Add(entityWebSite);
                }
            }

            // persist changes
            this.context.SaveChanges();

            string[] roles = { "Admin" };

            // Check is user is / or should be in admin role.
            if (isAdministrator == true)
            {
                if (!Roles.IsUserInRole(user.Username, "Admin"))
                {
                    Roles.AddUserToRoles(user.Username, roles);
                }
            }
            else
            {
                if (Roles.IsUserInRole(user.Username, "Admin"))
                {
                    Roles.RemoveUserFromRole(user.Username, "Admin");
                }
            }

            return ObjectExtension.CloneProperties<ScheduMail.DBModel.aspnet_Users, ScheduMail.Core.Domain.AspnetUsers>(entityUser);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the rule violations.
        /// </summary>
        /// <param name="webSite">The web site.</param>
        /// <returns>Collection of Rules Violations.</returns>
        private NameValueCollection GetRuleViolations(ScheduMail.Core.Domain.WebSite webSite)
        {
            var errors = new NameValueCollection();

            if (string.IsNullOrEmpty(webSite.SiteName))
            {
                errors.Add("SiteName", "Site Name is required");
            }

            if (webSite.SiteName.Length > 255)
            {
                errors.Add("SiteName", "Site Name max length exceeded");
            }

            if (string.IsNullOrEmpty(webSite.Template))
            {
                errors.Add("Template", "Template is required");
            }

            return errors;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Deletes the specified web site.
 /// </summary>
 /// <param name="webSite">The web site.</param>
 public void Delete(ScheduMail.Core.Domain.WebSite webSite)
 {
     this.repository.Delete(webSite);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Deletes the specified web site.
        /// </summary>
        /// <param name="webSite">The web site.</param>
        public void Delete(ScheduMail.Core.Domain.WebSite webSite)
        {
            var entity = (from w in this.context.WebSites.Include("Mail.LogEvent")                          
                          where w.Id == webSite.Id
                          select w).First();

            this.context.DeleteObject(entity);
            //// debug statement to check cascading delete changes.
            //// var oses = context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted);

            this.context.SaveChanges();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Deletes the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public void Delete(ScheduMail.Core.Domain.WebSite entity)
 {
     throw new NotImplementedException();
 }      
Exemplo n.º 11
0
        /// <summary>
        /// Gets the rule violations.
        /// </summary>
        /// <param name="schedule">The web site.</param>
        /// <returns>Collection of Rules Violations.</returns>
        private NameValueCollection GetRuleViolations(ScheduMail.Core.Domain.Schedule schedule)
        {
            var errors = new NameValueCollection();

            if (schedule.StartDateTime == null)
            {
                errors.Add("StartDateTime", "Start date is required");
            }

            if (string.IsNullOrEmpty(schedule.DailyWeeklyOrMonthly))
            {
                errors.Add("DailyWeeklyOrMonthly", "Please check the time to run");
            }
            if (Convert.ToString(schedule.DailyWeeklyOrMonthly) == "3" )
            {
                if (string.IsNullOrEmpty(schedule.DaysOfWeekToRun))
                {
                    errors.Add("DaysOfWeekToRun", "Please check days of the week");
                }
            }

            return errors;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Updates the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="originalEntity">The original entity.</param>
 /// <returns>Updated WebSite instance.</returns>
 public ScheduMail.Core.Domain.WebSite Update(ScheduMail.Core.Domain.WebSite entity, ScheduMail.Core.Domain.WebSite originalEntity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
 /// <summary>
 /// Saves the specified user.
 /// </summary>
 /// <param name="webSite">The website instance.</param>
 /// <returns>Changed user.</returns>
 public ScheduMail.Core.Domain.AspnetUsers Save(ScheduMail.Core.Domain.AspnetUsers webSite)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 14
0
 /// <summary>
 /// Deletes the specified mail.
 /// </summary>
 /// <param name="schedule">The schedule instance.</param>
 public void Delete(ScheduMail.Core.Domain.Mail schedule)
 {
     this.repository.Delete(schedule);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the rule violations.
        /// </summary>
        /// <param name="user">The users.</param>
        /// <returns>Collection of Rules Violations.</returns>
        private NameValueCollection GetRuleViolations(ScheduMail.Core.Domain.AspnetUsers user)
        {
            var errors = new NameValueCollection();

            if (user.Username.Length > 50)
            {
                errors.Add("Username", "Username is required");
            }

            if (String.IsNullOrEmpty(user.Email))
            {
                errors.Add("Username", "Username is required");
            }

            if (user.Email.Length > 50)
            {
                errors.Add("Email", "EMail is required");
            }

            if (String.IsNullOrEmpty(user.Email))
            {
                errors.Add("Email", "EMail is required");
            }

            return errors;
        }
Exemplo n.º 16
0
 public void Delete(ScheduMail.DBModel.User entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
 public ScheduMail.DBModel.User Update(ScheduMail.DBModel.User entity, ScheduMail.DBModel.User originalEntity, bool attach)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 18
0
 public ScheduMail.DBModel.User Save(ScheduMail.DBModel.User entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 19
0
 /// <summary>
 /// Saves or Updates the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>Saved instance.</returns>
 public ScheduMail.Core.Domain.LogEvent Save(ScheduMail.Core.Domain.LogEvent entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 20
0
        /// <summary>
        /// Deletes the specified user.
        /// </summary>
        /// <param name="user">The user instance.</param>
        public void Delete(ScheduMail.Core.Domain.AspnetUsers user)
        {
            var entity = (from u in this.context.aspnet_Users.Include("WebSite")
                          where u.UserId == user.UserId
                          select u).First();

            for (int i = 0; i < entity.WebSite.Count; i++)
            {
                entity.WebSite.Remove(entity.WebSite.ElementAt(0));
            }

            this.context.SaveChanges();
        }
Exemplo n.º 21
0
 /// <summary>
 /// Deletes the specified users.
 /// </summary>
 /// <param name="user">The user instance.</param>
 public void Delete(ScheduMail.Core.Domain.AspnetUsers user)
 {
     this.repository.Delete(user);
 }
Exemplo n.º 22
0
        /// <summary>
        /// Gets the rule violations.
        /// </summary>
        /// <param name="schedule">The mail instance.</param>
        /// <returns>Collection of Rules Violations.</returns>
        private NameValueCollection GetRuleViolations(ScheduMail.Core.Domain.Mail schedule)
        {
            var errors = new NameValueCollection();

            return errors;
        }
Exemplo n.º 23
0
        /// <summary>
        /// Deletes the specified web site.
        /// </summary>
        /// <param name="webSite">The web site.</param>
        public void Delete(ScheduMail.Core.Domain.Mail webSite)
        {
            var entity = (from w in this.context.Mails
                          where w.Id == webSite.Id
                          select w).First();

            this.context.DeleteObject(entity);
            this.context.SaveChanges();
        }