Ejemplo n.º 1
0
        public bool Update(SqlConnection connection, IInvitationModel model)
        {
            var id         = model.Id;
            var userid     = model.UserId;
            var invitation = model.Invitation;
            var date       = model.Date;
            var guestid    = model.GuestId;
            var status     = model.Status;

            if (id != 0)
            {
                var cmdText   = $"UPDATE {TableName} SET USERID=@userid, INVITATION=@invitation, DATE=@date, GUESTID=@guestid, STATUS=@status WHERE ID=@id";
                var myCommand = new SqlCommand(cmdText, connection);

                connection.Open();
                myCommand.Parameters.AddWithValue("@id", id);
                myCommand.Parameters.AddWithValue("@userid", userid);
                myCommand.Parameters.AddWithValue("@invitation", invitation);
                myCommand.Parameters.AddWithValue("@date", date);
                myCommand.Parameters.AddWithValue("@guestId", guestid);
                myCommand.Parameters.AddWithValue("@status", status);
                myCommand.ExecuteNonQuery();
                connection.Close();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public bool Delete(SqlConnection connection, IInvitationModel model)
        {
            var id         = model.Id;
            var invitation = model.Invitation;
            var guestid    = model.GuestId;

            if (id != 0)
            {
                var cmdText   = $"DELETE {TableName} WHERE ID=@id AND INVITATION=@invitation AND GUESTID=@guestid";
                var myCommand = new SqlCommand(cmdText, connection);

                connection.Open();
                myCommand.Parameters.AddWithValue("@id", id);
                myCommand.Parameters.AddWithValue("@invitation", invitation);
                myCommand.Parameters.AddWithValue("@guestid", guestid);
                myCommand.ExecuteNonQuery();
                connection.Close();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public bool DeleteInvitation(IInvitationModel model)
        {
            var connectionString = defaultConnection + $"database={databaseName};";
            var connection       = new SqlConnection(connectionString);

            return(invitationService.Delete(connection, model));
        }
Ejemplo n.º 4
0
        private void UserPageUI_OnUpdateInvitation(IInvitationModel invitationModel, IUserModel userModel)
        {
            var userId           = userModel.Id;
            var eventTableByDate = service.GetEventsByDate(invitationModel.Date);
            var hasEvent         = false;

            foreach (DataRow item in eventTableByDate.Rows)
            {
                if (Convert.ToInt32(item[1].ToString()) == userId)
                {
                    hasEvent = true;
                    break;
                }
            }

            if (invitationModel.Status == 1 && hasEvent)
            {
                MessageBox.Show("There is already an event on this day!");
            }
            else
            {
                if (service.UpdateInvitation(invitationModel))
                {
                    UpdateTables(userId);
                }
            }
        }
Ejemplo n.º 5
0
        public bool Create(SqlConnection connection, IInvitationModel model)
        {
            var userid     = model.UserId;
            var invitation = model.Invitation;
            var date       = model.Date;
            var guestid    = model.GuestId;
            var status     = model.Status;

            var cmdText   = $"INSERT INTO {TableName} (USERID, INVITATION, DATE, GUESTID, STATUS) VALUES (@userid, @invitation, @date, @guestid, @status)";
            var myCommand = new SqlCommand(cmdText, connection);

            connection.Open();
            myCommand.Parameters.AddWithValue("@userid", userid);
            myCommand.Parameters.AddWithValue("@invitation", invitation);
            myCommand.Parameters.AddWithValue("@date", date);
            myCommand.Parameters.AddWithValue("@guestId", guestid);
            myCommand.Parameters.AddWithValue("@status", status);
            myCommand.ExecuteNonQuery();
            connection.Close();

            return(true);
        }
Ejemplo n.º 6
0
 public bool DeleteInvitation(IInvitationModel model) => sqlService.DeleteInvitation(model);
Ejemplo n.º 7
0
 public bool UpdateInvitation(IInvitationModel model) => sqlService.UpdateInvitation(model);
Ejemplo n.º 8
0
 public bool CreateInvitation(IInvitationModel model) => sqlService.CreateInvitation(model);