コード例 #1
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.Sales.FirstOrDefault(w => w.ID == command.SaleID);

                db.Entry(item);
                item.StateID = db.States.Where(s => s.Name == "Deleted").FirstOrDefault().ID;
                db.SaveChanges();

                response.ID      = item.ID;
                response.Success = true;
                response.Message = "Deleted state.";
            }
            catch
            {
            }

            return(response);
        }
コード例 #2
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.States.FirstOrDefault(w => w.ID == command.StateID);

                db.States.Remove(item);

                db.SaveChanges();

                response.ID = item.ID;
                response.Success = true;
                response.Message = "Deleted state.";
            }
            catch
            {
                // log error
            }

            return response;
        }
コード例 #3
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.Users.FirstOrDefault(w => w.ID == command.User.ID);

                if (item == null)
                {
                    item              = command.User;
                    item.ID           = Guid.NewGuid();
                    item.RegDate      = DateTime.Now;
                    item.PasswordHash = TAuth.Hash(item.PasswordHash);
                    item.State        = db.States.Where(s => s.Name == "Active").FirstOrDefault();
                    item.StateID      = db.States.Where(s => s.Name == "Active").FirstOrDefault().ID;

                    if (item.Role == null)
                    {
                        item.Role   = db.Roles.Where(r => r.Name == "User").FirstOrDefault();
                        item.RoleID = db.Roles.Where(r => r.Name == "User").FirstOrDefault().ID;
                    }
                    db.Users.Add(item);
                }
                else
                {
                    db.Entry(item);
                    item.Name    = command.User.Name;
                    item.Email   = command.User.Email;
                    item.RoleID  = command.User.RoleID;
                    item.StateID = command.User.StateID;
                    item.RegDate = command.User.RegDate;
                }

                db.SaveChanges();

                response.ID              = item.ID;
                response.Success         = true;
                response.ResponseObjects = new List <object>
                {
                    item.Name,
                    item.Role
                };
                response.Message = "Saved state.";
            }
            catch
            {
            }

            return(response);
        }
コード例 #4
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.Sales.FirstOrDefault(w => w.ID == command.Sale.ID);

                if (item == null)
                {
                    item                   = command.Sale;
                    command.Sale.ID        = Guid.NewGuid();
                    command.Sale.User      = db.Users.Where(u => u.ID == item.UserID).FirstOrDefault();
                    command.Sale.Spectacle = db.Spectacles.Where(s => s.ID == item.SpectacleID).FirstOrDefault();
                    command.Sale.State     = db.States.Where(s => s.Name == "Active").FirstOrDefault();
                    command.Sale.StateID   = command.Sale.State.ID;
                    command.Sale.RegDate   = DateTime.Now;

                    db.Sales.Add(command.Sale);
                }
                else
                {
                    db.Entry(item);
                    item.Amount      = command.Sale.Amount;
                    item.UserID      = command.Sale.UserID;
                    item.SpectacleID = command.Sale.SpectacleID;
                    item.StateID     = command.Sale.StateID;
                    item.RegDate     = command.Sale.RegDate;
                }

                db.SaveChanges();

                response.ID      = item.ID;
                response.Success = true;
                response.Message = "Saved state.";
            }
            catch
            {
            }

            return(response);
        }
コード例 #5
0
        public CommandResponse Execute()
        {
            var db = new TheatreUZContext();

            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.Notifications.FirstOrDefault(w => w.ID == command.Notification.ID);

                if (item == null)
                {
                    command.Notification.ID = Guid.NewGuid();
                    db.Notifications.Add(command.Notification);
                }
                else
                {
                    db.Entry(item);
                    item.Message = command.Notification.Message;
                    item.UserID  = command.Notification.UserID;
                    item.StateID = command.Notification.StateID;
                    item.RegDate = command.Notification.RegDate;
                }

                db.SaveChanges();

                response.ID      = item.ID;
                response.Success = true;
                response.Message = "Saved state.";
            }
            catch
            {
            }

            return(response);
        }
コード例 #6
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.Genres.FirstOrDefault(w => w.ID == command.Genre.ID);

                if (item == null)
                {
                    command.Genre.ID = Guid.NewGuid();
                    db.Genres.Add(command.Genre);
                }
                else
                {
                    item.Name            = command.Genre.Name;
                    item.StateID         = command.Genre.StateID;
                    item.RegDate         = command.Genre.RegDate;
                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();

                response.ID      = item.ID;
                response.Success = true;
                response.Message = "Saved state.";
            }
            catch
            {
            }

            return(response);
        }
コード例 #7
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.States.FirstOrDefault(w => w.ID == command.State.ID);

                if (item == null)
                {
                    command.State.ID = Guid.NewGuid();
                    db.States.Add(command.State);
                }
                else
                {
                    db.Entry(item);
                    item.Name = command.State.Name;
                    item.RegDate = command.State.RegDate;
                }

                db.SaveChanges();

                response.ID = item.ID;
                response.Success = true;
                response.Message = "Saved state.";
            }
            catch
            {
                // log error
            }

            return response;
        }
コード例 #8
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.Spectacles.FirstOrDefault(w => w.ID == command.Spectacle.ID);

                command.Spectacle.Genre = db.Genres.Where(g => g.ID == command.Spectacle.GenreID).FirstOrDefault();
                command.Spectacle.State = db.States.Where(s => s.ID == command.Spectacle.StateID).FirstOrDefault();

                if (item == null)
                {
                    command.Spectacle.ID = Guid.NewGuid();
                    db.Spectacles.Add(command.Spectacle);
                }
                else
                {
                    if (item.PlayDate != command.Spectacle.PlayDate || item.GenreID != command.Spectacle.GenreID ||
                        item.Cost != command.Spectacle.Cost || item.Name != command.Spectacle.Name ||
                        item.StateID != command.Spectacle.StateID)
                    {
                        SmtpClient client = new SmtpClient()
                        {
                            EnableSsl   = true,
                            Host        = "smtp.mail.ru",
                            Credentials = new NetworkCredential("*****@*****.**", "testpassword123")
                        };

                        List <string> emails = db.Sales.Where(s => s.SpectacleID == command.Spectacle.ID).Select(u => u.User.Email).ToList();

                        MailMessage msg = new MailMessage
                        {
                            From    = new MailAddress("*****@*****.**"),
                            Subject = "Warning from Central theatre of Uzbekistan",
                            Body    = string.Format("Some informations of spectacle which you booked recently was changed.\nOld information:\nName: {0}\nGenre: {1}\nPlay date: {2}\nCost: {3}\n\nNew information:\nName: {4}\nGenre: {5}\nPlay date: {6}\nCost: {7}",
                                                    item.Name, item.Genre.Name, item.PlayDate, item.Cost,
                                                    command.Spectacle.Name, command.Spectacle.Genre.Name, command.Spectacle.PlayDate, command.Spectacle.Cost)
                        };

                        emails.ForEach(e => msg.To.Add(e));

                        client.Send(msg);
                    }

                    db.Entry(item);
                    item.Name         = command.Spectacle.Name;
                    item.Cost         = command.Spectacle.Cost;
                    item.TicketsCount = command.Spectacle.TicketsCount;
                    item.PlayDate     = command.Spectacle.PlayDate;
                    item.GenreID      = command.Spectacle.GenreID;
                    item.StateID      = command.Spectacle.StateID;
                    item.RegDate      = command.Spectacle.RegDate;
                }

                db.SaveChanges();

                response.ID      = item.ID;
                response.Success = true;
                response.Message = "Saved state.";
            }
            catch
            {
            }

            return(response);
        }